Skip to content

Commit 9eadd62

Browse files
committed
update_20210115
1 parent c4fc4d3 commit 9eadd62

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

09mq/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<dependency>
2828
<groupId>org.apache.activemq</groupId>
2929
<artifactId>activemq-all</artifactId>
30-
<version>5.16.0</version>
30+
<version>5.15.6</version>
3131
</dependency>
3232

3333
<dependency>

09mq/src/main/java/io/kimmking/javacourse/mq/activemq/ActivemqApplication.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
import org.springframework.boot.SpringApplication;
88
import 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;
1117
import 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

Comments
 (0)