Introduction To MQ Clients
Introduction To MQ Clients
WebSphere MQ Clients
Morag Hughson
IBM Hursley
[email protected]
Agenda
What is a client ?
MQ
MQ
Queue
Queue
Manager
Manager
However.....
No
No network
network No
No messaging.
messaging.
MQ
MQClient
Client
Application
Application
What is a client ?
In this world of client/server architectures, thin-clients, thick-clients and network
clients the word client is a much overused word which means different things to
different people.
N
O
T
E
S
Messaging Clients
MQI
JMS
.NET
Java
Direct IP &
Multicast
WebSphere
WebSphere
Platform
Platform
Messaging
Messaging
WebSphere
WebSphere
MQ
MQ
WBI
WBI
Event
Event Broker
Broker
Message
Message Broker
Broker
XMS
C
C++
C#
WMQE
WMQE
WMQE
(.NET)
Messaging Clients
There are a number of messaging clients designed to suit different
environments, different programming languages and different programming
languages.
N
C
C++
C#
Java
COBOL
Etc..
N
O
T
E
S
The decision as to which client to use often comes down to which one fits in best
with the current application environment. For example, if an enterprise codes all of
its applications in Java then clearly choosing one of the Java clients would be
sensible rather than using JNI to call the C client.
The other major decision is what programming model should be used. This comes
down to choosing between the MQI and JMS. The MQI is particular to WebSphere
MQ and while it is extremely common and powerful it is not provided by any other
messaging provider. As a consequence porting an application written to the MQI to
another provider would require considerable effort. JMS is the standard way of doing
messaging in a Java environment and, as such, applications written to JMS should
port easily to another provider. Note, however, than a JMS application on one
provider can not necessarily communicate with a JMS application on another
provider.
What is an MQ Client ?
Server
Model
Application
MQ Server
Library
Inter process
Communications
MQ
Server
Client
Model
Application
MQ Client
Library
Network
Communications
MQ
Server
What is an MQ Client ?
The WebSphere MQ Client support is part of the WebSphere MQ product
that can be installed and used separately from the MQ server. It provides a
set of libraries which can be linked with your applications to provide access
to WebSphere MQ queues without requiring the application to run on the
same machine as the queues.
N
O
T
E
MQI Channel
MQ Client
Library
Application
MQI Calls
MQCONN
MQOPEN
MQPUT
MQCB
MQINQ
MQCMIT
MQCONNX
MQCLOSE
MQPUT1
MQCTL
MQSET
MQBACK
MQDISC
MQSUB
MQGET
N
O
T
E
S
All the standard MQI functions, except MQBEGIN, are available to clients.
The key MQI call at this point is clearly MQCONN(X). It is this call which
determines either directly or indirectly which Queue Manager the application
will try to connect to. Well cover this in more detail later lets assume that
we manage to connect to a Queue Manager somewhere.
As the application issues each MQI call, MQ client code directs the request
to the queue manager over the communication link. The MQI request is
essentially serialised, sent over the communications link. The server
receives the request and issues the request on behalf of the client
application. It then send back a reply to the client.
The surrogate application issuing these requests on behalf of the client is a
running channel of type SVRCONN. Each remotely connected client will
have a SVRCONN channel running on its behalf. It is possible to have many
thousands of these channels running into a single Queue Manager.
12
General Index
https://www-304.ibm.com/support/docview.wss?uid=swg27007197
MQC7 MQ V7 Clients
https://www-304.ibm.com/support/docview.wss?uid=swg24019253
MQC6 MQ V6 Clients
https://www-304.ibm.com/support/docview.wss?uid=swg24009961
MQC5 MQ Client for VSE
https://www-304.ibm.com/support/docview.wss?uid=swg24010051
MQC4 MQ Client for OpenVMS
https://www-304.ibm.com/support/docview.wss?uid=swg24009031
14
O
T
E
S
16
N
O
T
E
S
For further information see See Chapter 11. Building applications for
WebSphere MQ clients
18
CLNTCONN
MQI Calls
Client machine
SVRCONN
Server machine
The client identifies which channel should be used when the application
issues an MQCONN/MQCONNX call.
The choice about which channel to use is made by checking the following (in
this order):
The ClientConnOffset or ClientConnPtr in the MQCNO structure (if an MQCONNX was issued).
The MQSERVER environment variable.
E
S
The client channel definition table. This can be found as described by the MQCHLLIB and
MQCHLTAB environment variables or using the Active Directory on Windows.
The channel definition table found in the default path.
Java clients don't use the above method. The standard MQ java classes use
the MQEnvironment class to identify the channel, while JMS clients use the
Java Naming and Directory Interface (JNDI) to identify channels.
20
MQCCSID
MQCHLLIB
MQCHLTAB
MQNAME
MQSSLKEYR
22
set MQSERVER=ChannelName/TransportType/ConnectionName
In Windows: use Control Panel -> System -> Advanced ->Environment Variables
In UNIX: export MQSERVER
Examples:
MQSERVER=SYSTEM.DEF.SVRCONN/TCP/127.0.0.1
MQSERVER=SYSTEM.DEF.SVRCONN/TCP/127.0.0.1(1415)
MQSERVER=SYSTEM.DEF.SVRCONN/TCP/JUPITER.SOLAR.SYSTEM.UNI
MQSERVER=SYSTEM.DEF.SVRCONN/LU62/BOX99
However, MQSERVER cannot be used if more advanced options are required on the
channel (such as SSL) and the variable has to be set on each client machine.
Use upper case for the transport type (TCP, LU62, NETBIOS, SPX).
If you dont youll get a 2058 reason code on the connect
24
You cannot append channel definition tables together. If you want to define
multiple client connection channels then you need to define all the channels
on one of the servers.
Channel definitions can be shared by more than one client. In other words,
the client definition table can be located on a file server.
E
S
To make a client channel definition table on z/OS you use the CSQUTIL
MAKECLNT function. For details see z/OS System Administration Guide.
26
AMQCLCHL.TAB
copy
c:\mqm\qmgrs\qmgrname\@ipcc\AMQCLCHL.TAB
to
z:\mytable.tbl
MYTABLE.TAB
N
O
T
E
S
28
MQCONN ("venus",hConn,cc,rc );
venus
chl2
AMQCLCHL.TAB
MQ Client
mars
N
O
T
E
S
The client searches through the client channels in alphabetical channel name order. It
looks for a channel definition with a QMNAME field which matches what the
application specified on the MQCONN call. We therefore find channel chl2. If we did
not find any channel definitions which match the application would receive a 2058
(Queue Manager name error) reason code.
The transmission protocol and associated connection are extracted from the channel
definition and an attempt is made to start the channel to the machine identified
(venus). In order for the connection to be successful clearly there must be started
listener at the remote machine and the queue manager itself must be started.
If the connection can not be established then a 2059 (Queue Manager not available)
reason code is returned to the application. If you believe the Queue Manager is
running then look in the client error log for an error message explaining the reason for
the faliure.
The error log is in <mq install path>\errors\AMQERR01.LOG
30
MQCONN ("venus",hConn,cc,rc );
venus
chl2
AMQCLCHL.TAB
MQ Client
mars
T
E
Channel 'chl3' is now started instead because QMNAME still matches what
was specified on the MQCONN call.
32
MQCONN (planet",hConn,cc,rc );
mars
venus
AMQCLCHL.TAB
MQ Client
pluto
Finally the client tries to connect using channel "chl5". The communications
link is running and the queue manager is running.
O
T
E
S
However, the name of the queue manager "pluto" does not match the one
specified on the MQCONN call planet and so this connection fails.
There are no remaining client channel definitions and so the MQCONN call
fails with reason code MQRC_Q_MGR_NOT_AVAILABLE.
What we need is a way to tell MQ that we, the application, dont really care
what the actual Queue Manager name is.
34
MQCONN (*planet",hConn,cc,rc );
mars
venus
AMQCLCHL.TAB
MQ Client
This works !
Notice the * preceding the Queue Manager name
pluto
The * specifies that the client does not care if the actual name of the Queue
Manager does not match the name given.
O
T
E
S
36
MQCONN ( ,hConn,cc,rc );
mars
venus
AMQCLCHL.TAB
MQ Client
pluto
O
T
Now, since the application has not specified the name of the Queue
Manager there is no problem with whatever the target Queue Manager
happens to be. In other words, <blank> is equivalent to *.
E
S
38
40%
40%
venus
20%
MQCONN(*planet)
pluto
Name
CHLTYPE
TRPTYPE
CONNAME
QMNAME
CLNTWGHT
AFFINITY
chl1
CLNTCONN
TCP
ip.mars
planet
PREFERRED
chl2
CLNTCONN
TCP
ip.venus
planet
PREFERRED
chl3
CLNTCONN
TCP
ip.pluto
planet
PREFERRED
New in
in
New
MQ V6
V7
MQ
You can define these destinations with a weighting so that the spread of client
connections between the group of queue managers is as you require.
You can then use the same CCDT with all your clients no need to produce different
copies of the CCDT to spread out your client connections across all the back-end
servers.
The default value of CLNTWGHT is 0 which retains the V6 behaviour of primary
then secondary choices chosen by alphabetical order.
By default client channels have AFFINITY(PREFERED) set. This means that any
particular client application will attempt to connect to the same queue manager each
time. This is the same behaviour that was available in V6 with the mechanism that the
primary connection was attempted first, then if it was not available, the secondary
connection was attempted, and so on. If it is desired that connections from the same
machine are to be workload balanced as above, AFFINITY(NONE)
can be chosen.
40
New in
in
New
MQ V6
V7
MQ
MAXINST restricts the number of instances in total for the specific channel
name.
T
E
42
Using MQCONNX
MQCONNX ( qmgr name, CNO, Hconn, cc, rc)
MQCNO - Connection Options:
MQCHAR4 StrucId;
MQLONG
Version;
MQLONG
Options;
. . .
MQLONG
ClientConnOffset;
MQPTR
ClientConnPtr;
. . .
/* Structure identifier
/* Structure version number
/* Options that control the action of MQCONNX
*/
*/
*/
ChannelName[20];
*/
ConnectionName[264];
/* Connection name
*/
Using MQCONNX
See Chapter 8. Using channels and Chapter 10. Using the message queue
interface (MQI)
N
O
T
E
S
The MQCD definition can either be provided via a pointer or via an offset.
The offset field is for those languages which often dont have pointers such
as COBOL.
You can provide SSL related information in the MQSCO structure of the
MQCONNX call.
See sample amqscnxc.
44
Using MQCONNX
MQCD cd = {MQCD_CLIENT_CONN_DEFAULT};
cno.Version = MQCNO_VERSION_2;
cno.ClientConnPtr = &cd;
strcpy(cd.ChannelName,"SYSTEM.DEF.SVRCONN);
strcpy(cd.ConnectionName,"VENUS.SOLAR.SYSTEM.UNI);
Using MQCONNX
The ClientConnOffset or ClientConnPtr can be used to specify the location of
the channel definition structure. In order for the location to be picked up by
the client the version of the MQCNO structure must be 2 or greater.
N
O
T
The details about the channel can now be placed in the MQCD structure.
Note: MQCNO_STANDARD_BINDING and MQCNO_FASTPATH_BINDING
are ignored when calling MQCONNX from a client. Whether the channel
actually runs using standard or fastpath is controlled via the MQIBINDTYPE
setting in the server configuration.
E
S
46
N
O
T
E
S
Dont forget about the error logs. Both the client and the server machine
have error logs which will tell you why an MQCONN is failing.
Try your configuration with a tried and trusted application such as the
sample AMQSPUTC.
Check that the server you are trying to connect to is available, the network
connection is available, that the queue manager is running and that a
listener for that queue manager has been started.
Check that you have correctly identified the whereabouts of your channel
definition table.
48
MQ Java Client
Java classes for accessing MQ
JVM
JMS Applications
(Server) JNI
TCP/IP (Client)
MQ Java Client
The MQ Java client can be used to access a server directly using the Java
Native Interface (JNI) or as a client using the TCP/IP protocol.
The MQ Java interface maps fairly closely to the MQI in many ways,
however a JMS interface which complies with Sun standards is also
provided.
JMS is a simpler, higher-level API, although it does offer some facilities not
available in the MQ API. For example: the publish/subcribe model, and
message selectors.
E
S
50
MQEnvironment.properties.put( MQC.TRANSPORT_PROPERTY,
MQC.TRANSPORT_MQSERIES);
MQEnvironment.hostname = "VENUS.SOLAR.SYSTEM.UNI";
MQEnvironment.channel = "SYSTEM.DEF.SVRCONN";
try
{
MQQueueManager qmgr = new MQQueueManager("");
}
catch (MQException ex) { ex.printStackTrace(System.err);}
N
O
The presence of a non blank hostname informs the client that the bindings
mode (direct server connection) cannot be used.
The other MQEnvironment variables (such as channel) can be used to
configure the client connection to the queue manager.
T
E
S
52
import com.ibm.mq.*;
MQEnvironment.properties.put( MQC.TRANSPORT_PROPERTY,
MQC.TRANSPORT_MQSERIES);
URL chanTab = new URL(ftp://ftp.server/mq/AMQCHLCL.TAB);
try
{
MQQueueManager qmgr = new MQQueueManager(venus,chanTab);
}
catch (MQException ex) { ex.printStackTrace(System.err);}
N
O
The presence of a non blank hostname informs the client that the bindings
mode (direct server connection) cannot be used.
The other MQEnvironment variables (such as channel) can be used to
configure the client connection to the queue manager.
T
E
S
54
N
O
The application provides the location of a context where objects are placed
which can be used by JMS to start a connection to a queue manager.
The QueueConnectionFactory object can contain a channel name and other
details which identify how the application is to connect to a queue manager.
T
E
S
56
Programming Considerations
Take care when specifying the queue manager name on MQCONN if using client
channel definition table...
Most MQI calls are SYNCHRONOUS and tend to be slower than in a server
environment.
Always be prepared for MQRC_CONNECTION_BROKEN.
Always code MQGMO_FAIL_IF_QUIESCING.
For optimum performance dont use really short lived connections (MQCONNs)
Carefully code MQWI_UNLIMITED on MQGET calls.
Use Asynchronous MQPUT and Read Ahead if appropriate
Programming Considerations
In general the rules for programming clients is the same as for local applications.
However, effects tend to be exaggerated calls are slower, more can go wrong and
windows tend to be larger..
N
O
T
E
S
Because theres a real network and the Queue Manager is usually on a different
machine than the client a client is much more likely to receive an
MQRC_CONNECTION_BROKEN reason code from an MQI call. Be prepared for this
and deal with it appropriately.
The most expensive call is the MQCONN itself. For optimum performance it is
imperative you dont connect too often and do a reasonable amount of work under
each connection.
As in local applications make sure all the processing of messages you care about are
done under a transaction. This means MQPUT and MQGET calls should use the
SYNCPOINT option. Failure to do so could lead to messages becoming lost. This
behaviour tends to be more obvious in the client environment because the failure
windows are much larger.
If large numbers of non-persistent messages are involved it is worth considering
using Asynchronous MQPUT and/or Read Ahead to avoid a line turnaround from the
client per message.
58
Transactions
MQ Client
MQ Server
MQGMO_GET WAIT +
Application
MQGMO_NO_SYNCPOINT
MQGMO_GET WAIT +
MQGMO_NO_SYNCPOINT
Dies!
Message Arrives
Message Is Lost!
Transactions
This slide demonstrates the last point on the Programming Considerations slide.
Message data can be lost if applications end while performing an MQGET with wait
without being in syncpoint:
An application issues an MQGET with MQWI_UNLIMITED, but not in syncpoint.
There are currently no messages available on the server so the server starts waiting for one to arrive.
Meanwhile, the application ends unexpectedly before the MQGET returns.
O
T
E
S
A message now arrives, so the server gets it from the queue to send it to the application.
The server finds the application dead and so the message is discarded.
By getting messages in syncpoint if they are not correctly delivered they will
not be discarded.
It is recommended that an application always explicitly states MQGMO_SYNCPOINT
or MQGMO_NO_SYNCPOINT because the syncpoint default varies between
servers. (z/OS the default is syncpoint, Distributed the default is no syncpoint).
The key point here, though, is that the syncpoint model for local and client
machines is identical.
60
Global Transactions
MQPUT/GET
EXEC SQL
MQ
MQ
Server
Server
Database
Database
Server
Server
SQL COMMIT
MQCMIT
Global Transactions
The MQ client available for free download can only commit a unit of work
carried out on the queue manager it is connected to. The client cannot be
used to manage work carried out on other resource managers. Therefore
the MQBEGIN call is not available within normal MQ clients.
N
O
T
E
S
62
Local
Application
XA
TM
App
Database
client
NODE 1
Extended
Transactional
Client
NODE 2
Extended MQ
Client
XA
TM
Database Server
Queue
Manager
NODE 3
App
Database
client
NODE 1
Database Server
NODE 2
N
O
T
E
S
64
Client Security
Client
Server
Transport (Security)
SSL
Userid (real)
from
Environment
Security
Userid to Exit
Security
Client Security
See Chapter 7. Setting up WebSphere MQ client security.
Channel security exits
The channel security exits for client to server communication can work in the same way as for
server to server communication. A protocol independent pair of exits provide mutual
authentication of both the client and the server.
N
If the MQ server and client are both on Windows NT/2K/XP, and if the MQ
server has access to the domain on which the client user ID is defined, MQ
supports user IDs of up to 20 characters.
On all other platforms and configurations, the maximum length
for user IDs is 12 characters.
66
DEF CHANNEL('SYSTEM.DEF.CLNTCONN')
CHLTYPE(CLNTCONN)
SSLCIPH('RC4_MD5_US')
SSLPEER('CN=user", O="IBM",C="UK"')
SSL facility
key repository
MQSSLKEYR
environment variable
Client
Authentication,
Encryption, Integrity
SSL facility
key repository
Server
The Secure Sockets Layer (SSL) provides an industry standard protocol for
transmitting data in a secure manner over an insecure network. The SSL protocol is
widely deployed in both Internet and Intranet applications. SSL defines methods for
authentication, data encryption, and message integrity for a reliable transport
protocol, usually TCP/IP.
O
T
E
S
SSL can be enabled on client channels by specifying a CipherSpec on the client and
server connection channel definitions.
SSL cannot be used if using the MQSERVER environment variable.
If using the MQCNO structure to pass in the client channel on an MQCONNX call, a
CipherSpec can be set in the MQCD structure.
If using Active Directory on Windows you can use the setmqcsp control command to
publish the client-connection channel definitions in Active Directory. One or more of
these definitions can specify the name of a CipherSpec.
68
Exits
Server
Client
MQCONN(..)
Security
Security
MQOPEN(..)
MQPUT(..)
Send
Receive
Receive
Send
Exits
The ExitPath stanza of the ini file determines location of exits, if not fully qualified
on the DEF CHL command
Add to mqs.ini which is installed with both the server and the client.
N
Client :
ClientExitPath:
ExitsDefaultPath=path
Server:
ExitPath:
ExitsDefaultPath=path
O
T
E
S
70
Summary
Clients are a simple, low administration and cheap way of
providing queuing throughout your network.
Consider which client to use based on
Programming Language required (C,Java,C#, C++)
Programming model required (MQI vs JMS)
Performance
Further Information
WebSphere MQ Information Center
Main index
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp
MQ Client information
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzaf.doc/cs10120_.htm
O
T
WebSphere MQ SupportPacs:
General Index
https://www-304.ibm.com/support/docview.wss?uid=swg27007197
MQC7 MQ V7 Clients
https://www-304.ibm.com/support/docview.wss?uid=swg24019253
MQC6 MQ V6 Clients
https://www-304.ibm.com/support/docview.wss?uid=swg24009961
MQC5 MQ Client for VSE
https://www-304.ibm.com/support/docview.wss?uid=swg24010051
MQC4 MQ Client for OpenVMS
https://www-304.ibm.com/support/docview.wss?uid=swg24009031
72