Commit 0131ed198c179aa50143ce630ec85ff519f80153
1 parent
1e4cababc3
Exists in
master
and in
6 other branches
commit
Showing 4 changed files with 0 additions and 167 deletions
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/jms/producer/SimpleMessageProducer.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/jms/receiver/SimpleMessageReceiver.java
- platform-operate-api/src/main/resources/spring/consumer-jms-context.xml
- platform-operate-api/src/main/resources/spring/producer-jms-context.xml
platform-operate-api/src/main/java/com/lyms/platform/operate/web/jms/producer/SimpleMessageProducer.java
View file @
0131ed1
1 | -package com.lyms.platform.operate.web.jms.producer; | |
2 | - | |
3 | -import java.util.Date; | |
4 | - | |
5 | -import javax.jms.JMSException; | |
6 | -import javax.jms.Message; | |
7 | -import javax.jms.Session; | |
8 | -import javax.jms.TextMessage; | |
9 | - | |
10 | -import org.slf4j.Logger; | |
11 | -import org.slf4j.LoggerFactory; | |
12 | -import org.springframework.jms.core.JmsTemplate; | |
13 | -import org.springframework.jms.core.MessageCreator; | |
14 | - | |
15 | -public class SimpleMessageProducer { | |
16 | - | |
17 | - private static final Logger LOG = LoggerFactory.getLogger(SimpleMessageProducer.class); | |
18 | - | |
19 | - protected JmsTemplate jmsTemplate; | |
20 | - | |
21 | - protected int numberOfMessages = 100; | |
22 | - | |
23 | - public void setNumberOfMessages(int numberOfMessages) { | |
24 | - this.numberOfMessages = numberOfMessages; | |
25 | - } | |
26 | - | |
27 | - public JmsTemplate getJmsTemplate() { | |
28 | - return jmsTemplate; | |
29 | - } | |
30 | - | |
31 | - public void setJmsTemplate(JmsTemplate jmsTemplate) { | |
32 | - this.jmsTemplate = jmsTemplate; | |
33 | - } | |
34 | - | |
35 | - public void sendMessages(String sendType) throws JMSException { | |
36 | - if ("jmsSend".equalsIgnoreCase(sendType)) { | |
37 | - jmsSendMessages(); | |
38 | - } else if ("convertAndSend".equalsIgnoreCase(sendType)) { | |
39 | - convertAndSendMessages(); | |
40 | - } | |
41 | - } | |
42 | - | |
43 | - public void convertAndSendMessages() throws JMSException { | |
44 | - final StringBuilder buffer = new StringBuilder(); | |
45 | - | |
46 | - for (int i = 0; i < numberOfMessages; ++i) { | |
47 | - buffer.append("Message '").append(i).append("' sent at: ").append(new Date()); | |
48 | - jmsTemplate.convertAndSend(buffer.toString()); | |
49 | - } | |
50 | - } | |
51 | - | |
52 | - public void jmsSendMessages() throws JMSException { | |
53 | - final StringBuilder buffer = new StringBuilder(); | |
54 | - | |
55 | - for (int i = 0; i < numberOfMessages; ++i) { | |
56 | - buffer.append("Message '").append(i).append("' sent at: ").append(new Date()); | |
57 | - | |
58 | - final int count = i; | |
59 | - final String payload = buffer.toString(); | |
60 | - | |
61 | - jmsTemplate.send(new MessageCreator() { | |
62 | - public Message createMessage(Session session) throws JMSException { | |
63 | - TextMessage message = session.createTextMessage(payload); | |
64 | - message.setIntProperty("messageCount", count); | |
65 | - LOG.info("Sending message number '{}'", count); | |
66 | - return message; | |
67 | - } | |
68 | - }); | |
69 | - } | |
70 | - } | |
71 | - | |
72 | -} |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/jms/receiver/SimpleMessageReceiver.java
View file @
0131ed1
1 | -package com.lyms.platform.operate.web.jms.receiver; | |
2 | - | |
3 | -import javax.jms.Message; | |
4 | -import javax.jms.MessageListener; | |
5 | - | |
6 | -import org.slf4j.Logger; | |
7 | -import org.slf4j.LoggerFactory; | |
8 | -import org.springframework.jms.core.JmsTemplate; | |
9 | - | |
10 | -public class SimpleMessageReceiver implements MessageListener { | |
11 | - | |
12 | - private static final Logger LOG = LoggerFactory.getLogger(SimpleMessageReceiver.class); | |
13 | - | |
14 | - protected JmsTemplate jmsTemplate; | |
15 | - | |
16 | - public JmsTemplate getJmsTemplate() { | |
17 | - return jmsTemplate; | |
18 | - } | |
19 | - | |
20 | - public void setJmsTemplate(JmsTemplate jmsTemplate) { | |
21 | - this.jmsTemplate = jmsTemplate; | |
22 | - } | |
23 | - | |
24 | - public void receive(String receiveType) { | |
25 | - if ("jmsReceive".equalsIgnoreCase(receiveType)) { | |
26 | - jmsReceive(); | |
27 | - } else if ("receiveAndConvert".equalsIgnoreCase(receiveType)) { | |
28 | - receiveAndConvert(); | |
29 | - } | |
30 | - } | |
31 | - | |
32 | - public void jmsReceive() { | |
33 | - Message message = jmsTemplate.receive(); | |
34 | - LOG.debug("Received a JMS message: {}", message); | |
35 | - } | |
36 | - | |
37 | - public void receiveAndConvert() { | |
38 | - String message = (String) jmsTemplate.receiveAndConvert(); | |
39 | - LOG.debug("Received a text message: {}", message); | |
40 | - } | |
41 | - | |
42 | - @Override | |
43 | - public void onMessage(Message message) { | |
44 | - | |
45 | - } | |
46 | -} |
platform-operate-api/src/main/resources/spring/consumer-jms-context.xml
View file @
0131ed1
1 | -<?xml version="1.0" encoding="UTF-8"?> | |
2 | -<beans xmlns="http://www.springframework.org/schema/beans" | |
3 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
4 | - xmlns:jms="http://www.springframework.org/schema/jms" | |
5 | - xmlns:p="http://www.springframework.org/schema/p" | |
6 | - xsi:schemaLocation=" | |
7 | - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd | |
8 | - http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd"> | |
9 | - | |
10 | - <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" | |
11 | - p:brokerURL="tcp://localhost:61616" /> | |
12 | - | |
13 | - <bean id="destination" class="org.apache.activemq.command.ActiveMQQueue"> | |
14 | - <constructor-arg value="TEST.FOO" /> | |
15 | - </bean> | |
16 | - | |
17 | - <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" | |
18 | - p:connectionFactory-ref="connectionFactory" | |
19 | - p:defaultDestination-ref="destination" | |
20 | - p:receiveTimeout="1000" /> | |
21 | - | |
22 | - <bean id="messageReceiver" class="org.bsnyder.spring.jms.receiver.SimpleMessageReceiver" | |
23 | - p:jmsTemplate-ref="jmsTemplate" /> | |
24 | - | |
25 | -</beans> |
platform-operate-api/src/main/resources/spring/producer-jms-context.xml
View file @
0131ed1
1 | -<?xml version="1.0" encoding="UTF-8"?> | |
2 | -<beans xmlns="http://www.springframework.org/schema/beans" | |
3 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
4 | - xmlns:jms="http://www.springframework.org/schema/jms" | |
5 | - xmlns:p="http://www.springframework.org/schema/p" | |
6 | - xsi:schemaLocation=" | |
7 | - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd | |
8 | - http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd"> | |
9 | - | |
10 | - <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" | |
11 | - p:brokerURL="tcp://localhost:61616" /> | |
12 | - | |
13 | - <bean id="destination" class="org.apache.activemq.command.ActiveMQQueue"> | |
14 | - <constructor-arg value="TEST.FOO" /> | |
15 | - </bean> | |
16 | - | |
17 | - <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" | |
18 | - p:connectionFactory-ref="connectionFactory" | |
19 | - p:defaultDestination-ref="destination" /> | |
20 | - | |
21 | - <bean id="messageProducer" class="org.bsnyder.spring.jms.producer.SimpleMessageProducer" | |
22 | - p:jmsTemplate-ref="jmsTemplate" /> | |
23 | - | |
24 | -</beans> |