parent
4fdda6d204
commit
285e58bfcf
8 changed files with 133 additions and 33 deletions
@ -0,0 +1,16 @@ |
|||||||
|
package com.lq.jms.service; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author qi |
||||||
|
*/ |
||||||
|
public interface ProductService { |
||||||
|
|
||||||
|
/** |
||||||
|
* 发送队列消息 |
||||||
|
* @param topic 主题 |
||||||
|
* @param msg 消息内容 |
||||||
|
*/ |
||||||
|
void sendQueue(String topic,String msg); |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
package com.lq.jms.service.impl; |
||||||
|
|
||||||
|
import com.lq.jms.service.ProductService; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.jms.core.JmsTemplate; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author qi |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class ProductServiceImpl implements ProductService { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private JmsTemplate jmsTemplate; |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public void sendQueue(String topic, String msg) { |
||||||
|
|
||||||
|
jmsTemplate.convertAndSend(topic,msg); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -1,31 +1,37 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||||
<beans xmlns="http://www.springframework.org/schema/beans" |
<beans xmlns="http://www.springframework.org/schema/beans" |
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
xmlns:context="http://www.springframework.org/schema/context" |
|
||||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc" |
|
||||||
xmlns:jee="http://www.springframework.org/schema/jee" |
|
||||||
xmlns:tx="http://www.springframework.org/schema/tx" |
|
||||||
xmlns:aop="http://www.springframework.org/schema/aop" |
|
||||||
xmlns:mvc="http://www.springframework.org/schema/mvc" |
|
||||||
xmlns:util="http://www.springframework.org/schema/util" |
|
||||||
xmlns:amq="http://activemq.apache.org/schema/core" |
|
||||||
xmlns:jms="http://www.springframework.org/schema/jms" |
|
||||||
xsi:schemaLocation=" |
xsi:schemaLocation=" |
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd |
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd |
||||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd |
|
||||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd |
|
||||||
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd |
|
||||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd |
|
||||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd |
|
||||||
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd |
|
||||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd |
|
||||||
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.0.xsd |
|
||||||
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.14.5.xsd |
|
||||||
"> |
"> |
||||||
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory" > |
|
||||||
<property name="brokerURL" value="tcp://localhost:61616"/> |
<!-- ActivieMQ的连接工厂 --> |
||||||
|
<bean id="targetConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory" > |
||||||
|
<property name="brokerURL" value="tcp://127.0.0.1:61616"/> |
||||||
|
</bean> |
||||||
|
<!-- spring jms 为我们提供的连接池 获取一个连接工厂 --> |
||||||
|
<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory"> |
||||||
|
<property name="targetConnectionFactory" ref="targetConnectionFactory"/> |
||||||
</bean> |
</bean> |
||||||
|
|
||||||
|
<!-- 消息目的地 消息队列模式--> |
||||||
|
<bean id="queueDestination" class="org.apache.activemq.command.ActiveMQQueue"> |
||||||
|
<constructor-arg value="SpringActiveMQMsg"/> |
||||||
|
</bean> |
||||||
|
|
||||||
|
<!-- jms 消息模版 --> |
||||||
|
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> |
||||||
|
<property name="connectionFactory" ref="connectionFactory"/> |
||||||
|
<!-- 默认主题 --> |
||||||
|
<property name="defaultDestination" ref="queueDestination"/> |
||||||
|
<!-- true:消息队列模式 false:订阅发布模式 默认:true--> |
||||||
|
<property name="pubSubNoLocal" value="true"/> |
||||||
|
<!-- 发送超时--> |
||||||
|
<property name="receiveTimeout" value="10000"/> |
||||||
|
</bean> |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</beans> |
</beans> |
@ -0,0 +1,25 @@ |
|||||||
|
package com.lq.code.dto; |
||||||
|
|
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
import static org.junit.Assert.*; |
||||||
|
|
||||||
|
public class QueueDtoTest { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void add() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void pop() { |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void hasNext() { |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void getIndex() { |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue