spring rabbitmq集成
pom.xml加
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
<version>1.7.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>1.7.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>http-client</artifactId>
<version>1.1.1.RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.2.0.RELEASE</version>
</dependency>
<!--公司的封装rabbitmq工具-->
<dependency>
<groupId>com.yonyou.f4</groupId>
<artifactId>common</artifactId>
<version>1.2.2</version>
</dependency>
2.War打包时 有些包不会打进去,统一放在了D:\tools\f4\apache-tomcat-8.0.36\shared\lib下,如果pom新dependcy包不起作用检查下是否在不打包的列表中,如是手工复制到tomcat-8.0.36\shared\lib下,比如在使用rabbitmq时用到spring-rabbit.jar 和spring-retry-1.2.0.RELEASE.jar需复制过去,不然启动时报错
3.spring xml
<?xml version="1.0" encoding="UTF-8"?>
<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:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-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/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/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit.xsd"> <!-- <context:component-scan base-package="com.yonyou.dms.web.controller" /> -->
<!-- <bean -->
<!-- class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> -->
<!-- <property name="viewResolvers"> -->
<!-- <list> -->
<!-- <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" /> -->
<!-- <bean -->
<!-- class="org.springframework.web.servlet.view.InternalResourceViewResolver"> -->
<!-- <property name="prefix" value="/WEB-INF/jsp/" /> -->
<!-- <property name="suffix" value=".jsp" /> -->
<!-- </bean> -->
<!-- </list> -->
<!-- </property> -->
<!-- <property name="defaultViews"> -->
<!-- <list> -->
<!-- JSON View -->
<!-- <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" /> --> <!-- XML View -->
<!-- <bean class="org.springframework.web.servlet.view.xml.MarshallingView"> -->
<!-- <property name="marshaller"> -->
<!-- <bean class="org.springframework.oxm.xstream.XStreamMarshaller" /> -->
<!-- </property> -->
<!-- </bean> -->
<!-- </list> -->
<!-- </property> -->
<!-- </bean> --> <!-- 换成如下写法 -->
<!-- <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" -->
<!-- p:messageConverters-ref="messageConverters"> -->
<!-- </bean> -->
<!-- <util:list id="messageConverters"> -->
<!-- <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter" /> -->
<!-- <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" /> -->
<!-- <bean class="org.springframework.http.converter.StringHttpMessageConverter" > -->
<!-- <property name="supportedMediaTypes"> -->
<!-- <list> -->
<!-- <value>text/plain;charset=UTF-8</value> -->
<!-- <value>text/html;charset=UTF-8</value> -->
<!-- </list> -->
<!-- </property> -->
<!-- </bean> -->
<!-- <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" /> -->
<!-- <bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter" -->
<!-- p:marshaller-ref="xmlMarshaller" p:unmarshaller-ref="xmlMarshaller"> -->
<!-- </bean> -->
<!-- <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> -->
<!-- <property name="supportedMediaTypes"> -->
<!-- <list> -->
<!-- <value>application/json; charset=UTF-8</value> -->
<!-- <value>application/x-www-form-urlencoded; charset=UTF-8</value> -->
<!-- <value>multipart/form-data; charset=UTF-8</value> -->
<!-- </list> -->
<!-- </property> -->
<!-- <property name="objectMapper"> -->
<!-- <bean class="com.yonyou.dms.framework.filter.XssObjectMappper" id="XssObjectMappper"/> -->
<!-- </property> -->
<!-- </bean> -->
<!-- </util:list> -->
<!-- <bean id="xmlMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"> -->
<!-- <property name="streamDriver"> -->
<!-- <bean class="com.thoughtworks.xstream.io.xml.StaxDriver" /> -->
<!-- </property> -->
<!-- </bean> --> <beans profile="source">
<mvc:annotation-driven validator="validator">
<mvc:message-converters>
<bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter" />
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" id="MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json; charset=UTF-8</value>
<value>application/x-www-form-urlencoded; charset=UTF-8</value>
<value>multipart/form-data; charset=UTF-8</value>
</list>
</property>
<property name="objectMapper">
<bean class="com.yonyou.dmsgms.framework.filter.XssObjectMappper" id="XssObjectMappper"/>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven> <!-- upload settings -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="5242880"></property>
<property name="resolveLazily" value="true"/>
</bean> <!-- 国际化配置 -->
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver" >
<property name="cookieName" value="language"></property>
</bean> <bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>messages/webValidate</value>
<value>messages/manageValidate</value>
<value>messages/customerValidate</value>
<value>messages/partValidate</value>
<value>messages/repairValidate</value>
<value>messages/vehicleValidate</value>
<value>messages/retailValidate</value>
<value>messages/commonASValidate</value>
<value>messages/commonValidate</value>
</list>
</property>
</bean> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>
<!-- 这里配置将使用上面国际化配置的messageSource -->
<property name="validationMessageSource" ref="messageSource"/>
</bean> <!-- 权限拦截 -->
<bean id="aclInterceptor" class="com.yonyou.f4.common.acl.interceptor.AclInterceptor">
<property name="aclUserParamName" value="${f4.mvc.aclUser.key}"></property>
<property name="anonymUID" value="${f4.mvc.aclUser.anonymUID}"></property>
<property name="tenantIdParamName" value="${f4.mvc.tenant.key}"></property>
<property name="aclManager" ref="aclManager"></property>
<property name="preRes" ref="prepareResouce"></property>
<property name="errorPage" value="error.jsp"></property>
<!-- <property name="exclude"> -->
<!-- <value><![CDATA[.*\.(js|css|jpg|htm|html|woff|bmp|jpeg|png|gif){1}]]></value> -->
<!-- </property>不做权限验证 -->
</bean>
<bean id="prepareResouce" class="com.yonyou.dmsgms.framework.interceptors.acl.DmsPrepareResourceImpl">
</bean>
<bean id="aclManager" class="com.yonyou.f4.common.acl.impl.AclManagerImpl">
<property name="cacheExpireTime" value="30"></property><!-- 单位分钟 -->
<!-- <property name="redisFactory" ref="jedisFactory"></property> -->
<property name="provider" ref="aclDataProvider"></property>
</bean>
<bean id="aclDataProvider" class="com.yonyou.dmsgms.framework.interceptors.acl.AclDmsDataProvider"></bean> <!-- DMS 系统拦截器 -->
<bean id="dmsFrameworkInterceptor" class="com.yonyou.dmsgms.framework.interceptors.DMSFrameworkInterceptor"/> <!-- mvc 配置 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<ref bean="dmsFrameworkInterceptor"/>
</mvc:interceptor>
<!-- <mvc:interceptor> -->
<!-- <mvc:mapping path="/**"/> -->
<!-- <ref bean="aclInterceptor"/> -->
<!-- </mvc:interceptor> -->
</mvc:interceptors> <!-- 权限拦截 --> <!-- <bean id="viewResolver" -->
<!-- class="org.springframework.web.servlet.view.UrlBasedViewResolver"> -->
<!-- <property name="viewClass" -->
<!-- value="org.springframework.web.servlet.view.JstlView" /> -->
<!-- <property name="prefix" value="/html/error/" /> -->
<!-- <property name="suffix" value=".html" /> -->
<!-- </bean> --> <bean id="jsonFactory" class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean">
<property name="failOnEmptyBeans" value="false"/>
<property name="indentOutput" value="true"/>
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg value="yyyy-MM-dd HH:mm:ss"/>
</bean>
</property>
<property name="featuresToDisable">
<array>
<value type="com.fasterxml.jackson.databind.DeserializationFeature">FAIL_ON_UNKNOWN_PROPERTIES</value>
</array>
</property>
</bean> <bean class="com.yonyou.f4.common.msg.impl.TopicProducerImpl" init-method="init">
<property name="connectionFactory" ref="rabbitmq_cf"/>
<property name="objectMapper" ref="jsonFactory"/>
<property name="topics">
<set>
<value>ms01.t1</value>
<value>ms01.t2</value>
</set>
</property>
</bean>
<bean class="com.yonyou.f4.common.msg.impl.TopicConsumerImpl" init-method="init" destroy-method="destroy">
<property name="connectionFactory" ref="rabbitmq_cf"/>
<property name="objectMapper" ref="jsonFactory"/>
<property name="maxThreads" value="10"/>
<property name="queues">
<map>
<entry key="ms01.c1">
<map>
<entry key="ms01.t1" value="ms01.user.login"/>
</map>
</entry>
</map>
</property>
<property name="handlers">
<map>
<entry key="ms01.user.login">
<bean class="com.yonyou.dms.web.controller.basedata.MsgHandler"/>
</entry>
<entry key="default">
<bean class="com.yonyou.dms.web.controller.basedata.MsgHandler"/>
</entry>
</map>
</property>
</bean> <rabbit:connection-factory id="rabbitmq_cf" host="10.180.6.182" username="admin" password="admin123" port="5672" virtual-host="gclub"/> </beans>
</beans>
spring rabbitmq集成的更多相关文章
- RabbitMQ(3) Spring boot集成RabbitMQ
springboot集成RabbitMQ非常简单,如果只是简单的使用配置非常少,springboot提供了spring-boot-starter-amqp项目对消息各种支持. 资源代码:练习用的代码. ...
- Spring boot集成RabbitMQ(山东数漫江湖)
RabbitMQ简介 RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统 MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出 ...
- spring boot Rabbitmq集成,延时消息队列实现
本篇主要记录Spring boot 集成Rabbitmq,分为两部分, 第一部分为创建普通消息队列, 第二部分为延时消息队列实现: spring boot提供对mq消息队列支持amqp相关包,引入即可 ...
- Spring Boot 集成 RabbitMQ 实战
Spring Boot 集成 RabbitMQ 实战 特别说明: 本文主要参考了程序员 DD 的博客文章<Spring Boot中使用RabbitMQ>,在此向原作者表示感谢. Mac 上 ...
- spring boot集成RabbitMQ
原文:https://www.jianshu.com/p/e1258c004314 RabbitMQ作为AMQP的代表性产品,在项目中大量使用.结合现在主流的spring boot,极大简化了开发过程 ...
- Spring Boot 集成RabbitMQ
在Spring Boot中整合RabbitMQ是非常容易的,通过在Spring Boot应用中整合RabbitMQ,实现一个简单的发送.接收消息的例子. 首先需要启动RabbitMQ服务,并且add一 ...
- 85. Spring Boot集成RabbitMQ【从零开始学Spring Boot】
这一节我们介绍下Spring Boot整合RabbitMQ,对于RabbitMQ这里不过多的介绍,大家可以参考网络上的资源进行安装配置,本节重点是告诉大家如何在Spring Boot中使用Rabbit ...
- spring boot 集成 rabbitmq 指南
先决条件 rabbitmq server 安装参考 一个添加了 web 依赖的 spring boot 项目 我的版本是 2.5.2 添加 maven 依赖 <dependency> &l ...
- Spring boot集成Rabbit MQ使用初体验
Spring boot集成Rabbit MQ使用初体验 1.rabbit mq基本特性 首先介绍一下rabbitMQ的几个特性 Asynchronous Messaging Supports mult ...
随机推荐
- CentOS7版本区别和下载
CentOS 7提供了三种ISO镜像文件的下载: DVD ISO 标准安装版,一般下载这个就可以了(推荐) Everything ISO 对完整版安装盘的软件进行补充,集成所有软件.(包含centos ...
- Optaplanner - 从探究示例中的hello world,初步认识规划引擎的运行步骤。
上一篇我们成功以把Opotaplanner规划引擎下载回来,并把它的示例运行起来,简单解析了一下它的Cloud balance示例.这一篇我们这些示例的源代码导入到Eclipse中,看看它在后台是怎么 ...
- ubuntu下的Nessus插件更新
00x1: 记录下nessus插件离线更新,免得每次度娘我Nessus是放在虚拟机里面. 00x2: nessus 插件更新地址: https://plugins.nessus.org/v2/offl ...
- CSS预处理语言
CSS预处理语言 Less,Sass,Stylus 安装 Less yarn add less 运行命令 ./node_modules/.bin/lessc 嵌套规则 Less.Sass嵌套规则一样 ...
- kubernetes学习笔记之七: Ingress-nginx 部署使用
一.Ingress 简介 在Kubernetes中,服务和Pod的IP地址仅可以在集群网络内部使用,对于集群外的应用是不可见的.为了使外部的应用能够访问集群内的服务,在Kubernetes 目前 提供 ...
- jmeter单sql语句测试
前提:在进行接口或者性能测试时需要用到数据库连接,此文讲解简单的单sql语句执行 步骤1:启动jmeter,新建一个测试计划,新建一个Thread(此处不作详细说明) 步骤2:再新建一个JDBC Co ...
- ubuntu搭建php开发环境记录
这两天自己在阿里云上面买了一个ecs,系统选的是ubuntu16.04,第一件事就是先搭环境,这次准备使用lamp组合. Apache安装 首先安装apache服务器,ubuntu下面使用apt-ge ...
- 用react编写一个可以编辑的表格
这只一个雏形,但是可以用了.难点是如何点击每行后面的编辑按钮,让当前行的格子都变成input. import {Component} from 'react' const Action = props ...
- STL里的内存池实现
这个貌似有点复杂,解决的主要问题 就是 减少 内存分配次数,减少用户态核心态切换中断次数,提高运行速度,预分配 和线程池一个道理,预分配 ////////////////////自由链表 union ...
- Android Studio2.0 教程从入门到精通Windows版 - 提高篇
第二篇我们开发了一个Hello World应用,并介绍Android Sutdio的界面和如何调试应用,接下来将介绍一些常用的快捷键和必备插件. 常用快捷键 代码跳转 描述:跳转是为了方便代码位置的定 ...