JMS——集成Spring千亿集团 - 千亿集团

JMS——集成Spring千亿集团

2019年02月16日10时30分37秒 | 作者: 醉波 | 标签: 监听,行列,代码 | 浏览: 18898

property name="environment" prop key="java.naming.provider.url" tcp://dggtsp35-eip:7222 /prop prop key="java.naming.factory.initial" com.tibco..... /prop prop key="java.naming.security.principal" EIP_EIP_COMMON /prop prop key="java.naming.security.credentials" EIP_EIP_COMMON /prop /property /bean !创立衔接工厂 bean id="targetConnectionFactory" property name="jndiTemplate" ref bean="emsJndiTemplate"/ /property property name="jndiName" value="GenericConnectionFactory"/ /bean bean id="emsConnectionFactory" property name="targetConnectionFactory" ref bean="targetConnectionFactory"/ /property property name="username" value="EIP_EIP_COMMON"/ property name="password" value="EIP_EIP_COMMON"/ /bean !创立发送/接纳行列 bean id="send/receive" property name="jndiTemplate" ref bean="emsJndiTemplate"/ /property property name="jndiName" value="dh.test"/ !行列称号 /bean !创立监听类 bean id="messageListener" / !创立监听容器 bean id="jmsContainer" property name="connectionFactory" ref="emsConnectionFactory"/ property name="destination" ref="send/receive"/ property name="messageListener" ref="messageListener" / /bean

 

2.发送代码

 

import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.Session;
import org.springframework.jms.core.MessageCreator;
import org.springframework.jms.core.JmsTemplate;
public class JmsQueueSender {
 private JmsTemplate jmsTemplate;
 private Queue queue;
 public void setConnectionFactory(ConnectionFactory cf) {
 this.jmsTemplate = new JmsTemplate(cf);
 public void setQueue(Queue queue) {
 this.queue = queue;
 public void simpleSend() {
 this.jmsTemplate.send(this.queue, new MessageCreator() {
 public Message createMessage(Session session) throws JMSException {
 return session.createTextMessage("hello queue world");
}

 

3.监听代码

 

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
public class ExampleListener implements MessageListener {
 public void onMessage(Message message) {
 if (message instanceof TextMessage) {
 try {
 System.out.println(((TextMessage) message).getText());
 catch (JMSException ex) {
 throw new RuntimeException(ex);
 else {
 throw new IllegalArgumentException("Message must be of type TextMessage");
}

 

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表千亿集团立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章