可能重複:
Using JMS to connect to IBM MQ如何發送和在使用IBM的WebSphere MQ接收消息
我知道JMS是由Sun和IBM WebSphere MQ提供的消息標準是JMS的實現。
我一直使用JMS並從未使用過MQ。所以我有幾個問題。
使用JMS我將配置應用程序服務器中的連接工廠和隊列,並使用以下代碼發送和接收消息。在JMS中,我們使用javax.jms。*包。
代碼發送消息
Context context = new InitialContext();
QueueConnectionFactory queueConnectionFactory =`enter code here`
(QueueConnectionFactory) context.lookup("QueueConnectionFactory");
String queueName = "MyQueue";
Queue queue = (Queue) context.lookup(queueName);
queueConnection =
queueConnectionFactory.createQueueConnection() ;
QueueSession queueSession =
queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender queueSender = queueSession.createSender(queue);
TextMessage message = queueSession.createTextMessage();
message.setText("This is a TextMessage");
queueSender.send(message) ;
代碼用於接收消息
Context context = new InitialContext();
QueueConnectionFactory queueConnectionFactory =(QueueConnectionFactory) context.lookup("QueueConnectionFactory");
String queueName = "MyQueue";
Queue queue = (Queue) context.lookup(queueName);
QueueConnection queueConnection =queueConnectionFactory.createQueueConnection() ;
QueueSession queueSession = queueConnection.createQueueSession (false, •*■ Session.AUTO_ACKNOWLEDGE) ;
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
queueConnection.start() ;
Message message = queueReceiver.receive(1) ;
請讓我知道我可以發送時使用IBM WebSphere MQ IAM收到的消息。 IBM提供任何API來幫助在使用IBM MQ時發送和接收消息嗎?
檢查此答案http://stackoverflow.com/questions/2324038/using-jms-to-connect-to-ibm-mq/3248980#3248980 –