0
我嘗試使用來自多個客戶端的消息並對他們作出響應,以便我收到消息,但是當第一個客戶端發送消息時,他沒有得到任何響應,其他客戶端也不能發送任何消息消息。就像我的消費者階層被鎖定一樣。任何想法爲什麼?消息使用者在第一條消息後被阻止
public class Consumer implements MessageListener {
private static ConnectionFactory factory = null;
private static Connection connection = null;
private static Session session = null;
private static Destination sendQueue = null;
private static Destination recieveQueue = null;
private static MessageConsumer consumer = null;
private static MessageProducer producer = null;
final static Logger logger = Logger.getLogger(Consumer.class);
public static void main(String[] args) {
try {
factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
connection = factory.createConnection();
connection.start();
session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
recieveQueue = session.createQueue("BookingQueue");
consumer = session.createConsumer(recieveQueue);
// JMSMessageListener listener = new JMSMessageListener();
// consumer.setMessageListener(listener);
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
}
@Override
public void onMessage(Message message) {
if (message instanceof ObjectMessage) {
ObjectMessage msg = (ObjectMessage)message;
Booking booking;
try {
booking = (Booking) msg.getObject();
logger.info("Received order for " + booking.getCustomer());
sendQueue = message.getJMSReplyTo();
producer = session.createProducer(sendQueue);
logger.info("# The Agent sending hello");
TextMessage messageNew = session.createTextMessage("Hello, please reply immediately to my message!");
messageNew.setJMSReplyTo(recieveQueue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
producer.send(messageNew);
consumer.close();
session.close();
connection.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}