我正在使用 Websphere java 类在我的应用程序中实现 jms。
发件人代码:
MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
connectionFactory.setHostName(environment.getProperty(MQ_CONNECTION_HOSTNAME));
connectionFactory.setPort(Integer.parseInt(environment.getProperty(MQ_CONNECTION_PORT)));
connectionFactory.setQueueManager(environment.getProperty(MQ_CONNECTION_QMANAGER));
connectionFactory.setChannel(environment.getProperty(MQ_CONNECTION_CHANNEL));
connectionFactory.setTransportType(1);
final String username = environment.getProperty(MQ_CONNECTION_USERNAME);
final String password = environment.getProperty(MQ_CONNECTION_PASSWORD);
MQQueueConnection connection = null;
if(username != null && username.trim().length() > 0 && password != null && password.trim().length() > 0) {
connection = (MQQueueConnection) connectionFactory.createQueueConnection(username, password);
}
else {
connection = (MQQueueConnection) connectionFactory.createQueueConnection();
}
senderSession = (MQQueueSession) connection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
MQQueue queue = (MQQueue) senderSession.createQueue("queue:///" + environment.getProperty(MQ_CONNECTION_QUEUE));
MQQueueSender sender = (MQQueueSender) senderSession.createSender(queue);
JMSMessage message = (JMSMessage)senderSession.createTextMessage(messageContent);
connection.start();
sender.send(message);
message.acknowledge()
收货人代码:
final MQQueueConnection connection = (MQQueueConnection) (useAuth ? connectionFactory.createQueueConnection(username, password) : connectionFactory.createQueueConnection());
connection.start();
final MQQueueSession receiverSession = (MQQueueSession) connection.createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
final MQQueue queue = MQQueue)receiverSession.createQueue(queueName);
MQQueueReceiver receiver = createReceiver(session, queue);
receiver.setMessageListener(listener);
当我使用这些设置发送消息时,消息侦听器永远不会收到任何消息。但是,当我打开两个会话时,交易为假,一切似乎都正常。我可以理解原因。我想要交易会话。
如果需要任何其他详细信息,请告诉我