- 浏览: 7249814 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (1546)
- 企业中间件 (236)
- 企业应用面临的问题 (236)
- 小布Oracle学习笔记汇总 (36)
- Spring 开发应用 (54)
- IBatis开发应用 (16)
- Oracle基础学习 (23)
- struts2.0 (41)
- JVM&ClassLoader&GC (16)
- JQuery的开发应用 (17)
- WebService的开发应用 (21)
- Java&Socket (44)
- 开源组件的应用 (254)
- 常用Javascript的开发应用 (28)
- J2EE开发技术指南 (163)
- EJB3开发应用 (11)
- GIS&Mobile&MAP (36)
- SWT-GEF-RCP (52)
- 算法&数据结构 (6)
- Apache开源组件研究 (62)
- Hibernate 学习应用 (57)
- java并发编程 (59)
- MySQL&Mongodb&MS/SQL (15)
- Oracle数据库实验室 (55)
- 搜索引擎的开发应用 (34)
- 软件工程师笔试经典 (14)
- 其他杂项 (10)
- AndroidPn& MQTT&C2DM&推技术 (29)
- ActiveMQ学习和研究 (38)
- Google技术应用开发和API分析 (11)
- flex的学习总结 (59)
- 项目中一点总结 (20)
- java疑惑 java面向对象编程 (28)
- Android 开发学习 (133)
- linux和UNIX的总结 (37)
- Titanium学习总结 (20)
- JQueryMobile学习总结 (34)
- Phonegap学习总结 (32)
- HTML5学习总结 (41)
- JeeCMS研究和理解分析 (9)
最新评论
-
lgh1992314:
[u][i][b][flash=200,200][url][i ...
看看mybatis 源代码 -
尼古拉斯.fwp:
图片根本就不出来好吧。。。。。。
Android文件图片上传的详细讲解(一)HTTP multipart/form-data 上传报文格式实现手机端上传 -
ln94223:
第一个应该用排它网关吧 怎么是并行网关, 并行网关是所有exe ...
工作流Activiti的学习总结(八)Activiti自动执行的应用 -
ZY199266:
获取不到任何消息信息,请问这是什么原因呢?
ActiveMQ 通过JMX监控Connection,Queue,Topic的信息 -
xiaoyao霄:
DestinationSourceMonitor 报错 应该导 ...
ActiveMQ 通过JMX监控Connection,Queue,Topic的信息
本文主要目的实现activemq和spring将消息写入数据库的方法:
activemq.xml的内容如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> <!-- Allows us to use system properties as variables in this configuration file --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> <broker useJmx="false" brokerName="jdbcBroker" xmlns="http://activemq.apache.org/schema/core"> <persistenceAdapter> <jdbcPersistenceAdapter dataDirectory="activemq-data" dataSource="#derby-ds"/> </persistenceAdapter> <transportConnectors> <transportConnector name="default" uri="tcp://localhost:61619"/> </transportConnectors> </broker> <bean id="derbyds" class="org.apache.activemq.store.jdbc.adapter.DB2JDBCAdapter"/> <!-- Embedded Derby DataSource Sample Setup --> <bean id="derby-ds" class="org.apache.derby.jdbc.EmbeddedDataSource"> <property name="databaseName" value="derbydb"/> <property name="createDatabase" value="create"/> </bean> </beans>
activemq-jdbc.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean"> <property name="config" value="classpath:activemq.xml"/> <property name="start" value="true"/> </bean> <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" depends-on="broker"> <property name="brokerURL" value="tcp://localhost:61619"/> </bean> </beans>
消息生产者:
package easyway.activemq.app.demo3; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import javax.jms.Connection; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.StreamMessage; import org.apache.activemq.ActiveMQConnectionFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * 消息的创建者 * @author longgangbai * */ public class StreamMsgProducer { public static void main(String[] args) { ClassPathXmlApplicationContext ctx=new ClassPathXmlApplicationContext("activemq-jdbc.xml"); ActiveMQConnectionFactory activeMqfactory=(ActiveMQConnectionFactory)ctx.getBean("connectionFactory"); Connection conn = null; try { conn = activeMqfactory.createConnection(); conn.start(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination queue = session.createQueue("streamMsg"); MessageProducer producer = session.createProducer(queue); File file=new File("C:\\send.txt"); InputStream in = new FileInputStream(file); byte[] buffer = new byte[2048]; int c = -1; while ((c = in.read(buffer)) > 0) { StreamMessage smsg = session.createStreamMessage(); smsg.writeBytes(buffer, 0, c); producer.send(smsg); System.out.println("send: " + c); } in.close(); } catch (JMSException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (conn != null) { try { conn.close(); } catch (JMSException e) { e.printStackTrace(); } } } } }
消息消费者:
package easyway.activemq.app.demo3; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import javax.jms.Connection; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.Session; import javax.jms.StreamMessage; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.xbean.BrokerFactoryBean; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * 消息的消费者 * @author longgangbai * */ public class StreamMsgConsumer { public void receive() { ClassPathXmlApplicationContext ctx=new ClassPathXmlApplicationContext("activemq-jdbc.xml"); ActiveMQConnectionFactory activeMqfactory=(ActiveMQConnectionFactory)ctx.getBean("connectionFactory"); Connection conn = null; try { conn = activeMqfactory.createConnection(); conn.start(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination queue = session.createQueue("streamMsg"); MessageConsumer consumer = session.createConsumer(queue); OutputStream out = new FileOutputStream("c:\\receive.txt"); byte[] buffer = new byte[2048]; while (true) { Message msg = consumer.receive(5000); if (msg == null) { break; } if (msg instanceof StreamMessage) { StreamMessage smsg = (StreamMessage) msg; int c = smsg.readBytes(buffer); out.write(buffer, 0, c); System.out.println("Receive: " + c); } } out.close(); } catch (JMSException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (conn != null) { try { conn.close(); } catch (JMSException e) { e.printStackTrace(); } } } } public static void main(String[] args) { new StreamMsgConsumer().receive(); } }
发表评论
-
ActiveMQ的拦截器插件
2011-07-22 09:29 6495ActiveMQ拦截器使用和原 ... -
ActiveMQ的各种表SQL的管理
2011-07-20 20:58 3398在ActiveMQ为了方便的切换数据库,更为了深入 ... -
ActiveMQ中advisory的使用和原理
2011-07-20 18:46 2853在ActiveMQ中的监控和管理也可以通过Advisory实现 ... -
ActiveMQ的异步转发(DispatchAsync)功能
2011-07-20 11:29 46581. 消息者异步转发功能 针对正常情况下,在一个 ... -
ActiveMQ 的独占消费(Exclusive Consumer)
2011-07-20 11:26 4053我们经常希望维持队列中的消息,按一定次序转发给消息者。然而当有 ... -
ActiveMQ5.5在Tomcat6.0中部署
2011-07-19 22:27 2884在ActiveMQ中监控管理Web组件为ActiveMQCon ... -
Window 下ActiveMQ端口冲突,负载均衡,主备配置
2011-07-17 16:03 5485在Java 学习中Window操作系 ... -
ActiveMQ中消息权限策略
2011-07-17 00:31 2617在ActiveMQ发送消息的时候,可以通过MessageAut ... -
ActiveMQ和Jetty整合使用
2011-07-07 22:49 5514在ActiveMQ中的activemq.b ... -
ActiveMQ 和Commons-Daemon整合
2011-07-07 20:13 2898在一般的java项目中,如果在linu ... -
关于ActiveMQ中怎么实现一对多发送消息讨论
2011-07-07 19:50 6019无 ... -
ActiveMQ 中ActiveMQBlobMessage的接收和发送
2011-07-05 10:47 5083在ActiveMQ中对比较大的消息采用一 ... -
ActiveMQ 和JAXWS整合
2011-07-04 22:02 2174在多个系统中可能考虑到远程访问等的,采用WebServ ... -
ActiveMQ-Camel的使用
2011-07-02 10:27 10157在一个电子系统中可能接受来自不同供应商的 ... -
ActiveMQ模板和Velocity整合使用
2011-07-01 19:50 2265ActiveMQ模板使用 在ActiveMQ中AMQ ... -
ActiveMQ中消息游标
2011-06-30 18:16 2620在 ActiveMQ 5.0的之前版本中,b ... -
ActiveMQ和Tomcat的整合应用
2011-06-30 17:00 11148在ActiveMQ的资源让容器Tomcat管理时 ... -
ActiveMQ关于文件传输需要注意哪些方面?
2011-06-18 22:11 6132最近一直在关注一些文件传输中间件的实现,想用Acti ... -
关于ActiveMQ中Session和Connection资源的管理
2011-06-15 23:43 25045配置完了持久化之后,我们就可以使用代码来发送 ... -
ActiveMQ中关于文件锁的机制的学习
2011-06-14 23:31 3238在ActiveMQ中提供了文件数据库机 ...
相关推荐
ActiveMQ与spring整合进行封装,实现全注解开发,并且支持topic与queue两种模式无缝切换,对外提供统一的接口调用,简化操作。对连接池进行优化,容器实例动态生成。
一个订阅通道,支持多个客户端监听,当某个客户端掉线后,再上线的时候可以收到它没有接收到的消息。
ActiveMQ的持久化(数据库)[归类].pdf
spring +activemq topic消息持久化订阅实例,整个项目中有activemq和spring的整合的所有实例,topic的持久化配置是在ApplicationContext3C、ApplicationContext3C2以及ApplicationContext3P三个中,消息生产者:...
activeMQ 和spring 整合 亲自测试过特别好的demo,推荐下载
ActiveMQ与Spring整合示例Demo,ActiveMQ安装在linux系统中
ActiveMQ配置Mysql8为持久化方式所需Jar包
Spring和ActiveMQ整合的完整实例
学习activemq spring 整合
spring整合JMS-居于ActiveMQ实现
将ActiveMQ和Spring进行了整合,是一个单项目的demo,可以根据其扩展为分布式项目
项目整合activemq spring 消息队列 订阅 关注消息项目整合activemq spring 消息队列 订阅 关注消息
activemq spring
百度spring整合activemq 发现几乎都只是在xml文件配置固定的消息队列而且太麻烦。并没有根据需求进行动态生成主题和队列。本文档参考了纯粹的activemq java代码和百度上的demo,很简洁的实现了动态消息队列的生成和...
本人在学习activemq,然后 测试完成的demo, 包含了queue,topic,持久化到mysql,订阅模式,包好用
activemq与spring的整合的简单案例,整体说明见博文:http://blog.csdn.net/u012897777/article/details/78748221
详细内容: SpringJMS整合ActiveMQ.doc 详细说明文档 apache-activemq-5.8.0-bin.zip ActiveMQ安装包 JMSTest.rar MyEclipse8.5下web工程
NULL 博文链接:https://showlike.iteye.com/blog/2000117
ActiveMQ与Spring线程池整合的一个实例。 lib库没有上传。 对于实例的讲解,在竹子的论坛有我对这个实例的帖子(http://www.java2000.net/viewthread.jsp?tid=1167) lib中包含: apache-activemq-4.1.1.jar ...