jboss6 ejb3 jms 集成的那些事
来源:互联网 发布:截图下载软件 编辑:程序博客网 时间:2024/04/30 14:06
在JBOSS_HOME\server\default\deploy\hornetq\hornetq-jms.xml后面加上
<queuename="testQueue">
<entryname="/queue/myqueue"/>
</queue>
<topicname="testTopic">
<entry name="/topic/mytopic"/>
</topic>
jms 实例
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName ="destinationType" , propertyValue="javax.jms.Queue"),
@ActivationConfigProperty(propertyName ="destination" , propertyValue="queue/myqueue")
})
public class HelloListener implements MessageListener {
public void onMessage(Message msg) {
TextMessage text = (TextMessage)msg;
String str;
try {
str = text.getText();
System.out.println("监听到了,Content:" + str);
} catch (JMSException e) {
e.printStackTrace();
}
}
}
客户端
public static void main(String[] args)throws Exception {
InitialContext cxt = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory)cxt.lookup("ConnectionFactory");
Queue queue = (Queue) cxt.lookup("queue/myqueue");
QueueConnection conn = factory.createQueueConnection();
QueueSession session = (QueueSession) conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
TextMessage text = session.createTextMessage("is_zhoufeng");
QueueSender sender = session.createSender(queue);
for (int i = 0; i < 100 ; i++) {
sender.send(text);
}
sender.close();
session.close();
conn.close();
}
@MessageDriven(activationConfig={
@ActivationConfigProperty(propertyName ="destinationType" , propertyValue="javax.jms.Topic"),
@ActivationConfigProperty(propertyName ="destination" , propertyValue="topic/mytopic")
})
public class TopicListener implements MessageListener{
public void onMessage(Message message) {
TextMessage text = (TextMessage)message;
try {
System.out.println("Topic监听器1:content:" + text.getText() );
} catch (JMSException e) {
e.printStackTrace();
}
}
}
客户端
public class TopicTest {
public static void main(String[] args)throws Exception {
InitialContext cxt = new InitialContext();
TopicConnectionFactory factory =(TopicConnectionFactory)cxt.lookup("ConnectionFactory");
Topic topic = (Topic) cxt.lookup("topic/mytopic");
TopicConnection conn = factory.createTopicConnection();
TopicSession session = (TopicSession) conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
TextMessage text =session.createTextMessage("is_zhoufeng");
TopicPublisher sender = session.createPublisher(topic);
sender.send(text);
sender.close();
session.close();
conn.close();
}
}
- jboss6 ejb3 jms 集成的那些事
- jboss6 + ejb3 jms 配置
- jboss6配置jms
- jboss6 jms 配置使用
- Jboss6 集成hibernate
- JMS的集成
- EJB3与Spring的集成
- springboot集成weblogic的jms
- 初识EJB3.0的MDB来开发JMS
- spring log4j 集成的那些事
- 集成趣拍SDK的那些事
- jboss6 quartz2.0.2集成配置使用
- jms activeMQ与spring的集成
- jms activeMQ与spring的集成
- spring学习:与jms的集成
- spring学习:与jms的集成
- struts2与spring集成启动的那些事
- JBoss6部署报 java.lang.IllegalStateException service=EJB3 is already installed 解决办法
- 常用的16个c/c++面试题
- 关于二进制文件fread、fwrite函数使用读写
- Java程序编译和运行过程图文解析
- C++ this指针
- Error Log(个人笔记)
- jboss6 ejb3 jms 集成的那些事
- Programming ASP.NET MVC 4 - Chap01 - ASP.NET MVC 基础
- JAVA基础
- 网络流题目总结
- 第七讲第三篇
- 深入体验JavaWeb开发内幕——pageContext对象与JSP中标签的简介和相关应用
- Android 计时器Timer用法
- Merge Sorted Array
- Boost线程库学习笔记