77import org .springframework .boot .SpringApplication ;
88import org .springframework .boot .autoconfigure .SpringBootApplication ;
99
10- import javax .jms .*;
10+ import javax .jms .Destination ;
11+ import javax .jms .Message ;
12+ import javax .jms .MessageConsumer ;
13+ import javax .jms .MessageListener ;
14+ import javax .jms .MessageProducer ;
15+ import javax .jms .Session ;
16+ import javax .jms .TextMessage ;
1117import java .util .concurrent .atomic .AtomicInteger ;
1218
1319
@@ -18,7 +24,7 @@ public static void main(String[] args) {
1824
1925 // 定义Destination
2026 Destination destination = new ActiveMQTopic ("test.topic" );
21- // Destination destination = new ActiveMQQueue("test.queue");
27+ // Destination destination = new ActiveMQQueue("test.queue");
2228
2329 testDestination (destination );
2430
@@ -28,7 +34,7 @@ public static void main(String[] args) {
2834 public static void testDestination (Destination destination ) {
2935 try {
3036 // 创建连接和会话
31- ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory ("tcp://127.0.0.1 :61616" );
37+ ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory ("tcp://120.79.218.62 :61616" );
3238 ActiveMQConnection conn = (ActiveMQConnection ) factory .createConnection ();
3339 conn .start ();
3440 Session session = conn .createSession (false , Session .AUTO_ACKNOWLEDGE );
@@ -37,6 +43,7 @@ public static void testDestination(Destination destination) {
3743 MessageConsumer consumer = session .createConsumer ( destination );
3844 final AtomicInteger count = new AtomicInteger (0 );
3945 MessageListener listener = new MessageListener () {
46+ @ Override
4047 public void onMessage (Message message ) {
4148 try {
4249 // 打印所有的消息内容
@@ -62,9 +69,9 @@ public void onMessage(Message message) {
6269 producer .send (message );
6370 }
6471
65- Thread .sleep (2000 );
66- session .close ();
67- conn .close ();
72+ // Thread.sleep(2000);
73+ // session.close();
74+ // conn.close();
6875
6976
7077 } catch (Exception e ) {
0 commit comments