- 浏览: 333759 次
- 性别:
- 来自: 北京
-
文章分类
最新评论
-
di1984HIT:
谢谢,写的不错。
使用hector操作Cassandra -
mr_von:
非常感谢!
paoding的分词使用 -
howgoo:
http://www.dhtmlx.com/docs/prod ...
dhtmlxGrid分页与排序 -
青春的、脚步:
谢谢
spring-data-mongodb的MongoTemplate 使用小例子 -
青春的、脚步:
xiaofancn 写道青春的、脚步 写道这个能查询都个值在某 ...
spring-data-mongodb的MongoTemplate 使用小例子
参考 http://blog.csdn.net/liuzhenwen/article/details/3768766
注意:Entity中有个Transient标注的属性无法序列化到queue中,可以用一个DTO重新组装对象传送。
定我们的Queue文件adServerLog-service.xml
<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=adServerQueue"> <attribute name="JNDIName">queue/adServerQueue</attribute> <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends> </mbean> </server>
applicationContext.xml的配置
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> <!-- This will automatically locate any and all property files you have within your classpath, provided they fall under the META-INF/spring directory. The located property files are parsed and their values can then be used within application context files in the form of ${propertyKey}. --> <context:property-placeholder location="classpath*:META-INF/spring/*.properties" /> <context:spring-configured /> <context:component-scan base-package="com.mogenesis"> <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" /> </context:component-scan> <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"> <property name="driverClassName" value="${database.driverClassName}" /> <property name="url" value="${database.url}" /> <property name="username" value="${database.username}" /> <property name="password" value="${database.password}" /> </bean> <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"> <property name="dataSource" ref="dataSource" /> <property name="persistenceXmlLocation" value="classpath*:/META-INF/persistence-spring.xml" /> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /> </property> </bean> <!-- JMS configure --> <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"> <property name="environment"> <props> <prop key="java.naming.factory.initial"> org.jnp.interfaces.NamingContextFactory </prop> <prop key="java.naming.provider.url">localhost:1099</prop> <prop key="java.naming.factory.url.pkgs"> org.jnp.interfaces:org.jboss.naming </prop> </props> </property> </bean> <bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiTemplate"> <ref bean="jndiTemplate" /> </property> <property name="jndiName"> <value>XAConnectionFactory</value> </property> </bean> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate102"> <property name="connectionFactory" ref="jmsConnectionFactory" /> <property name="defaultDestination" ref="destination" /> <!-- true for Topic false for Queue --> <property name="pubSubDomain"> <value>false</value> </property> <!-- message waiting time(ms) --> <property name="receiveTimeout"> <value>30000</value> </property> </bean> <bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiTemplate"> <ref bean="jndiTemplate" /> </property> <property name="jndiName"> <value>queue/adServerQueue</value> </property> </bean> <!-- and this is the message listener container --> <bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="jmsConnectionFactory" /> <property name="destination" ref="destination" /> <!-- 监听队列的bean声明在注解之中 --> <property name="messageListener" ref="adServerJmsQueueListener" /> </bean> </beans>
服务端监听类AdServerJmsQueueListener.java
package com.mogenesis.mobileadplatform.adserver.log; import javax.annotation.Resource; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.ObjectMessage; import org.springframework.jms.core.JmsTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.mogenesis.mobileadplatform.domain.AdRequest; import com.mogenesis.mobileadplatform.service.adserver.AdMetricsService; @Service("adServerJmsQueueListener") public class AdServerJmsQueueListener implements MessageListener { @Resource private JmsTemplate jmsTemplate; @Resource private AdMetricsService adMetricsService; public void onMessage(Message message) { ObjectMessage objMessage = (ObjectMessage) message; try { AdRequest adRequest = (AdRequest) objMessage.getObject(); adMetricsService.processAdMetrics(adRequest); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
客户端操作类AdServerJmsQueueSender.java
package com.mogenesis.mobileadplatform.adserver.log; import javax.annotation.Resource; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.ObjectMessage; import javax.jms.Session; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.MessageCreator; import org.springframework.stereotype.Component; import com.mogenesis.mobileadplatform.domain.AdRequest; @Component public class AdServerJmsQueueSender { @Resource private JmsTemplate jmsTemplate; public void sendMessage(final AdRequest adRequest) { jmsTemplate.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { ObjectMessage objMessage = session.createObjectMessage(); objMessage.setObject(adRequest); return objMessage; } }); } }
在我们需要的组件类中添加
@Resource private AdServerJmsQueueSender adServerJmsQueueSender;
就可以使用了。
其中项目jms.jar包和jboss的jms.jar包冲突,所以我把项目中pom.xml文件为,编译的时候使用,次jar包部署的时候不用打包进项目
<dependency> <groupId>jms</groupId> <artifactId>jms</artifactId> <version>1.1</version> <scope>provided</scope> </dependency>
发表评论
-
spring cloud gateway 全局过滤器。
2019-03-17 23:11 538spring cloud gateway 网关 ... -
elasticsearch 5.4搜索
2017-05-19 08:37 148@Test public void t ... -
netty简单的操作memcached
2017-04-19 18:59 992pom文件 <dependency> ... -
juc系列-Executor框架
2017-03-20 13:34 713转自 juc系列-Executor框架 什 ... -
ReentrantLock 类
2017-03-19 21:11 11.1 什么是reentrantlock java.u ... -
juc之CountDownLatch、CyclicBarrier和Semaphore例子
2017-03-19 17:23 849import java.util.concurren ... -
netty客户端与服务端例子
2017-03-12 20:07 2812package com.snailteam.nett ... -
freemaker集成spring
2017-02-26 19:00 581<bean id="freeMark ... -
spring集成Hessian插件配置改成自动注入。
2017-02-10 15:39 848原来的配置 <bean name="/ ... -
web开发模版
2017-02-09 14:42 0# Rules reminder: # DEBUG &l ... -
Java多线程
2017-02-04 14:39 525线程状态图 新建状态(New): ... -
hash冲突解决
2017-01-23 18:30 4791、开放地址法有一个公式: m是hash表长度,di ... -
mybatis +spring 分库
2015-04-30 17:56 353<context:component-scan b ... -
Java并发任务处理例子
2014-02-12 16:06 1148public void init() { su ... -
JAVA动态代理模式
2012-10-03 01:01 1207这是我要实现的效果 public static ... -
paoding的分词使用
2012-06-13 21:30 4877paoding下载 http://code.googl ... -
使用spring-hadoop操作hadoop
2012-05-20 02:12 32参考文章 http://blog.springsource. ... -
solr3.5集成paoding和位置搜索及对solrj的使用。
2012-04-28 02:12 2023http://xiaofancn.iteye.com/blog ... -
日期处理DateUtils
2012-03-24 09:47 4858import java.text.SimpleDateF ... -
Cassandra的数据分布情况测试
2012-03-16 15:09 20541、规划种子节点ip和Token值的对应 4个种子 ...
相关推荐
- 此外,**Spring** 还提供了事务管理、DAO支持、与各种O/R Mapping框架的集成等功能,以及对J2EE组件技术的支持,例如JavaMail、EJB、JMS和WebService等。 ### 3. Hibernate 框架 - **Hibernate** 是一个成熟的全...
1.4. Seam 和jBPM:待办事项列表(todo list)示例..................................................................................................... 32 1.4.1. 理解代码....................................
包括jBPM4扩展研发先决条件、深入jPDL和jBPM Service API、升级jBPM3到jBPM4、流程虚拟机原理、jBPM4的设计思想、随需而配jBPM4、异步工作执行器、深入jBPM4电子邮件支持、系统日志、jBPM4与Spring框架集成、jBPM4与...
### J2EE WEB 开发教程知识点详述 #### 第一章 J2EE的基本概念和规范 **1.1 J2EE定义** J2EE(Java 2 Platform, Enterprise ...后续章节将继续深入讨论J2EE的相关技术和框架,如JDBC、Struts、Hibernate、Spring等。
然而,为了确保系统的稳定运行和高效服务,仅仅掌握Spring、Hibernate等开发框架和技术是远远不够的。本文旨在深入探讨J2EE集群这一重要概念及其背后的技术原理,帮助读者更好地理解如何利用集群技术来提升系统的...