我正在尝试重用 a以使用与此IBM MQ 教程JMSContext
中所示相同的上下文发送多条消息。
context = cf.createContext();
destination = context.createQueue(QUEUE_NAME);
producer = context.createProducer();
for (int i = 1; i <= 5000; i++) {
try {
TextMessage message = context.createTextMessage("Message " + i + ".\n");
producer.send(destination, message);
} catch (Exception ignore) {}
}
context.close();
假设连接在某个时候断开。上下文会自动恢复还是我需要再次重建上下文?
更新 -
这是当前连接工厂的构建方式:
JmsFactoryFactory ff = JmsFactoryFactory.getInstance(JmsConstants.WMQ_PROVIDER);
JmsConnectionFactory cf = ff.createConnectionFactory();
cf.setStringProperty (CommonConstants.WMQ_HOST_NAME, config.getHost());
cf.setIntProperty (CommonConstants.WMQ_PORT, config.getPort());
cf.setStringProperty (CommonConstants.WMQ_CHANNEL, config.getChannel());
cf.setIntProperty (CommonConstants.WMQ_CONNECTION_MODE, CommonConstants.WMQ_CM_CLIENT);
cf.setStringProperty (CommonConstants.WMQ_QUEUE_MANAGER, config.getQueueManager());
cf.setBooleanProperty (JmsConstants.USER_AUTHENTICATION_MQCSP, false);
cf.setIntProperty (JmsConstants.PRIORITY, 0);
return cf.createContext();