Created a webpage where a user can paste their XML file and after clicking the submit option, the XML file will go to other system ( which is test environment). That system is basically running on IBM (MQ) and I have to use JMS for it. I have QUEUE, Port, host name. Does anyone has any similar example which I can use as direction?
Basically, this is what you will need to do:
Accept the XML mesaage from UI.
Create a MQ Connection factory with details of your port,host and queue.
Create a JMS connection from MQ Connection Factory.
Create a JMS session off the JMS connection.
Create a JMS message Producer off the JMS session.
Create a JMS TextMessage containing the XML file.
Send the message to the JMS queue via the producer.
Will try to add a code example in a while, in the meantime for each step you will be able to find multiple examples online.
Dont forget to close the JMS message producer, jms session and jms connection in the finally block as they are resources.
Related
I have a jms based webservice implemented in axis2 framework. It uses Tibco EMS for JMS queue and connection factory.
Currently I have defined the active EMS server connection in axis2.xml and works fine. However, if this server goes down for some reason, I need to update the ais2.xml manually to point to failover EMS server and then bounce my webservice.
How can I define both active and failover connection such that it switches automatically when active one goes down
Regards,
Rajesh
In TIBCO EMS you can define an FT URL using the following syntax :
tcp://server:port,tcp://server:port
For example :
tcp://server1:7222,tcp://server2:7222
I think you should be able to use such connection URL in your framework.
We are trying to connect to IBMMQ using CCDT file and JMS configuration.
We are able to connect to it but we have an issue here:
since we are using spring to set connection factory with CCDT file, this is initialized once at the start of the application, but unfortunately it picks only one queue manager at a time,i.e it sends all the messages to same queue manager and it does not load balance.
Though i observed, if i manually set the CCDT file before every request then its able to load balance the Queue Managers, ideally it looks to me Queue Manager is decided whenever i set the URL to CCDT file. which is wrong practice. My expectation was to initialize the connection factory with CCDT file and then this configuration will be able to load balance on its own.
Can you help me this?
This is the expected behavior. MQ does not load balance clients, it connection balances them. The connection is the single most time consuming API call and in the case of a mutually authenticated TLS connection can take seconds to complete. Therefore a good application design will attempt to connect once, then maintain that connection for the duration of the session. The JMS architecture and Spring framework both expect this pattern.
The way that MQ provides load distribution (again, not true balancing, but rather round-robin distribution) is that the client connects a hop away from a clustered destination queue. A message addressed to that clustered destination queue will round-robin among all the instances of that queue.
If it is a request-reply application, the thing listening for requests on these clustered queue instances addresses the reply message using the Reply-To QMgr and Reply-To Queue name from the requesting message. In this scenario the requestors can fail over QMgr to QMgr if they lose their connection. The systems of record listening on the clustered queues generally do not fail over across queue managers in order to ensure all queue instances are served and because of transaction recovery.
Short answer is that CCDT and MQ client in general are not where MQ load distribution occurs. The client should make a connection and hold it as long as possible. Client reconnect and CCDT are for connection balancing only.
Load distribution is a feature of the MQ cluster. It requires multiple instances of a clustered queue and these are normally a network hop away from the client app that puts the message.
I am working on a JMS client server app where client first send some data to server through a common queue for all clients and server gives respond to it in a temporary queue created by client itself.
I googled it but could not find how can I implement it in JMS 2 as the traditional approach of creating temporary queue is by using session but in JMS 2 I am using JMSContext through which I am creating producer and consumer.
My question is how and where
In the JMS 2.0 JMSContext API the createTemporaryQueue and createTemporaryTopic server the same role as the traditional versions did in the JMS 1.1 Session style. The JMSContext is really just wrapping the ideas of Connection and Session into one object.
You also have all the same methods create creating messages and setting JMSReplyTo on them, in the consumer you need to consume a Message instance and then use the getJMSReplyTo to get at the reply queue
I understand JMS as depicted by the following diagram:
(source: techhive.com)
Is there any way for me to access the underlying database using JMS or some other thing? Further, the JDBC connections that the JMS server maintains, can I add new connections in it so as to access other databases also and do CRUD operations on them? If yes, how?
Where did you get this from?
Normally JMS is used to send messages to queue (or topics). You have message producers that push messages in the queue and message consumers consume them and process it.
In your exemple it seems that you have multiple queues. One for the messages that need to be processed, and one for each client to retrieve the result the processing of its messages.
With JMS Server you don't necessarily have a database behind. Everything can stay in memory, or can be written to files. You will need database server behind only if you configure your JMS server to be persistent (and to assure that even if server/application crash your messages won't be lost). But in that case you will never have to interact with the database. Only the JMS server will and you will interact with the JMS server sending and consuming messages.
When there is a network problem which results in the client being disconnected from the JMS server, is there some other way to detect the problem other than waiting until the next JMS message being sent fails?
You can register an ExceptionListner with the JMS Connection using Connection.setExceptionListener(ExceptionListener)
The ExceptionListener will get notified of more problems than an actual disconnection, so you may have to filter the JMSException that gets passed to the listener.
ExceptionListener isn't necessarily enough. You also need to catch exceptions on any JMS calls you make (sending messages, for example). See Reconnecting JMS listener to JBossMQ
if your are running on MQ and looking to solve this problem, install a local MQ instance. More license but you will get guaranty delivery if your main corporate MQ goes down.
Other Option, use Spring and let the framework do the recovery of the connection.