ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
Topic(广播形式) ~~~ public class TestTopic { public static void TopicProduct() { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://10.10.20.52:61616"); try { Connection conn = connectionFactory.createConnection(); conn.start(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic t = session.createTopic("topic-test"); MessageProducer p = session.createProducer(t); TextMessage msg = session.createTextMessage("hello topic"); p.send(msg); p.close(); session.close(); conn.close(); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void TopicConsumer() { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://10.10.20.52:61616"); try { Connection conn = connectionFactory.createConnection(); conn.start(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic t = session.createTopic("topic-test"); MessageConsumer c = session.createConsumer(t); c.setMessageListener(new MessageListener(){ @Override public void onMessage(Message arg0) { TextMessage m = (TextMessage)arg0; try { String tm = m.getText(); System.out.println(tm); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); try { System.in.read(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } c.close(); session.close(); conn.close(); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } ~~~ 广播形式的持久化: