可能重复:
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 –