As an example of how to use WebSphere MQ Everyplace within the OSGi environment, we providedtwo example application bundles that are designed to work together in a simple scenario. The scenario consists of a client application and a server application. The Server simply sits and waits for messages and prints out any that it receives, the Client just sends one message. Within this scenario it is possible to have multiple Clients sending to the same Server or the same Client can be stopped and restarted to send another message to the Server. These bundles are explained in more detail below:
When this bundle is started an MQeQueueManager is created and started with a listener and default queues in memory. The Application code is then run in a new thread and waits for incoming messages using a message listener; any received messages are displayed in the console. This thread continues to listen until the bundle is stopped, at which time it stops and then deletes the MQeQueueManager.
When this bundle is started it checks to see if an MQeQueueManager is already running in the JVM, if so it assumes it is running in the same runtime as the server and so uses that queue manager. If no queue manager is detected then a new one is defined and started in memory and a connection definition and remote queue definition are setup to the server. Client application code is then run in a new thread which sends a single message to the server. No checks are made to ensure the message is received. If we created a new QueueManager for the Client, it is stopped and deleted when the bundle is stopped.
The source for the classes included in the bundles can be seen in the MQe\Java\examples\osgi directory. More details are given in the java doc for these classes.
Some points to note when running the applications:
However, you run the examples the following bundle is required by both the client and server and must be present on the bundle server. See the Configuration Guide for details on submitting bundles to a server.
To run the example you will need to first start the Server:
'MQeServerBundle - registering message listener'This means the server is ready for messages.
Next you need to run a client to send a message. There are two methods for runnning the client bundle:
By default the example expects both client and server to be on the same machine running with the receiver listening on port 8085. However, you can change the port and address of the server, that is run the server on a separate machine. Before the server is started, you can tell it which port to run on by setting the java system property, "examples.osgi.server.port". This can be set in the Runtime IDE by selecting "show runtime properties" from the drop down menu.
To tell the client the address and port that the server is listening on, set the "examples.osgi.server.address" and "examples.osgi.server.port" system properties before the client is started.