2011-08-26 154 views
1

可能重复:
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时发送和接收消息吗?

+0

检查此答案http://stackoverflow.com/questions/2324038/using-jms-to-connect-to-ibm-mq/3248980#3248980 –

回答

1

您需要设置一个JNDI命名服务来为Websphere MQ提供您的JMS对象。 Websphere MQ实用程序是JMSAdmin。如果您拥有Websphere Application Server,则可以使用“Websphere MQ消息传递提供程序”设置JMS资源(连接工厂和队列或主题)。请注意,Websphere MQ中定义的名称与JNDI名称不同:您选择的JNDI名称将在设置这些绑定时引用Websphere MQ的名称。