File tree Expand file tree Collapse file tree
src/main/java/io/byk/activemq Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+
2+ ## Week13 周四作业:
3+ ### 1. [ (必做)搭建 ActiveMQ 服务,基于 JMS,写代码分别实现对于 queue 和 topic 的消息生产和消费,代码提交到 github。] ( src/main/java/io/byk/activemq )
4+
5+ 使用` JmsMessagingTemplate ` 模板类来实现
6+
Original file line number Diff line number Diff line change 44import static io .byk .activemq .config .ActiveMqConfig .ACTIVE_MQ_QUEUE ;
55import static io .byk .activemq .config .ActiveMqConfig .ACTIVE_MQ_TOPIC ;
66
7- import java .util .Queue ;
8-
97import javax .annotation .Resource ;
108
119import org .springframework .boot .ApplicationArguments ;
1816import lombok .extern .slf4j .Slf4j ;
1917
2018/**
19+ * 启动类
20+ *
2121 * @author boyunkai <boyunkai@kuaishou.com>
2222 * Created on 2021-02-05
2323 */
@@ -35,11 +35,12 @@ public static void main(String[] args) {
3535
3636 @ Override
3737 public void run (ApplicationArguments args ) throws Exception {
38+ // 测试队列
3839 for (int i = 0 ; i < 10 ; i ++) {
3940 String message = "队列消息" + i ;
4041 queueProducer .sendMessage (ACTIVE_MQ_QUEUE , message );
4142 }
42-
43+ // 测试主题
4344 for (int i = 0 ; i < 10 ; i ++) {
4445 String message = "主题消息" + i ;
4546 topicPublisher .sendMessage (ACTIVE_MQ_TOPIC , message );
Original file line number Diff line number Diff line change 1212
1313/**
1414 * 队列生产者
15+ *
1516 * @author boyunkai <boyunkai@kuaishou.com>
1617 * Created on 2021-02-05
1718 */
Original file line number Diff line number Diff line change 99import org .springframework .jms .config .SimpleJmsListenerContainerFactory ;
1010
1111/**
12+ * ContainerFactor 配置
13+ *
1214 * @author boyunkai <boyunkai@kuaishou.com>
1315 * Created on 2021-02-05
1416 */
Original file line number Diff line number Diff line change 33import javax .annotation .Resource ;
44import javax .jms .Destination ;
55
6- import org .apache .activemq .command .ActiveMQQueue ;
76import org .apache .activemq .command .ActiveMQTopic ;
87import org .springframework .jms .core .JmsMessagingTemplate ;
98import org .springframework .stereotype .Service ;
109
11- import lombok .Getter ;
1210import lombok .extern .slf4j .Slf4j ;
1311
1412/**
15- * 队列生产者
13+ * 主题生产者
14+ *
1615 * @author boyunkai <boyunkai@kuaishou.com>
1716 * Created on 2021-02-05
1817 */
1918@ Service
2019@ Slf4j
21- @ Getter
2220public class TopicPublisher {
2321 // JMS 模板
2422 @ Resource
Original file line number Diff line number Diff line change 11package io .byk .activemq .topic ;
22
3- import static io .byk .activemq .config .ActiveMqConfig .ACTIVE_MQ_QUEUE ;
43import static io .byk .activemq .config .ActiveMqConfig .ACTIVE_MQ_TOPIC ;
54
65import org .springframework .jms .annotation .JmsListener ;
98import lombok .extern .slf4j .Slf4j ;
109
1110/**
12- * 队列消费者
11+ * 主题消费者
1312 *
1413 * @author boyunkai <boyunkai@kuaishou.com>
1514 * Created on 2021-02-05
1615 */
1716@ Service
1817@ Slf4j
1918public class TopicSubscriber {
20- @ JmsListener (destination = ACTIVE_MQ_TOPIC ,containerFactory = "myJmsContainerFactory" )
19+ @ JmsListener (destination = ACTIVE_MQ_TOPIC , containerFactory = "myJmsContainerFactory" )
2120 public void receiveMessage (String message ) {
2221 log .info ("<=========== 收到消息" + message );
2322 }
You can’t perform that action at this time.
0 commit comments