import javax.jms.*; ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection connection = factory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue("myQueue"); MessageProducer producer = session.createProducer(destination); TextMessage message = session.createTextMessage("Hello, JMS!"); producer.send(message); MessageConsumer consumer = session.createConsumer(destination); Message receivedMessage = consumer.receive(); if (receivedMessage instanceof TextMessage) { TextMessage textMessage = (TextMessage) receivedMessage; System.out.println("Received message: " + textMessage.getText()); } session.close(); connection.close();


上一篇:
下一篇:
切换中文