import javax.jms.*; public class JmsExample { public static void main(String[] args) throws JMSException { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection connection = connectionFactory.createConnection(); 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()); } connection.close(); } }


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