重构客户注册-基于ActiveMQ实现短信验证码生产者
生活随笔
收集整理的這篇文章主要介紹了
重构客户注册-基于ActiveMQ实现短信验证码生产者
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
重構目標:將bos_fore項目中的CustomerAction作為短信消息生產者,將消息發給ActiveMQ,創建一個單獨的SMS項目,作為短信息的消費者,從ActiveMQ獲取短信消息,調用第三方接口完成短信發送。
CustomerAction完整代碼:
spring的配置文件applicationContext-mq.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" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context"xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:task="http://www.springframework.org/schema/task"xmlns:amq="http://activemq.apache.org/schema/core"xmlns:jms="http://www.springframework.org/schema/jms"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsdhttp://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsdhttp://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsdhttp://www.springframework.org/schema/jmshttp://www.springframework.org/schema/jms/spring-jms.xsdhttp://activemq.apache.org/schema/corehttp://activemq.apache.org/schema/core/activemq-core-5.8.0.xsd "><!-- ActiveMQ 連接工廠 --><!-- 真正可以產生Connection的ConnectionFactory,由對應的 JMS服務廠商提供--><!-- 如果連接網絡:tcp://ip:61616;未連接網絡:tcp://localhost:61616 以及用戶名,密碼--><amq:connectionFactory id="amqConnectionFactory"brokerURL="tcp://localhost:61616" userName="admin" password="admin" /><!-- Spring Caching連接工廠 --><!-- Spring用于管理真正的ConnectionFactory的ConnectionFactory --> <bean id="mqConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"><!-- 目標ConnectionFactory對應真實的可以產生JMS Connection的ConnectionFactory --> <property name="targetConnectionFactory" ref="amqConnectionFactory"></property><!-- 同上,同理 --><!-- <constructor-arg ref="amqConnectionFactory" /> --><!-- Session緩存數量 --><property name="sessionCacheSize" value="100" /></bean><!-- Spring JmsTemplate 的消息生產者 start--><!-- 定義JmsTemplate的Queue類型 --><bean id="jmsQueueTemplate" class="org.springframework.jms.core.JmsTemplate"><!-- 這個connectionFactory對應的是我們定義的Spring提供的那個ConnectionFactory對象 --> <constructor-arg ref="mqConnectionFactory" /><!-- 非pub/sub模型(發布/訂閱),即隊列模式 --><property name="pubSubDomain" value="false" /></bean><!-- 定義JmsTemplate的Topic類型 --><bean id="jmsTopicTemplate" class="org.springframework.jms.core.JmsTemplate"><!-- 這個connectionFactory對應的是我們定義的Spring提供的那個ConnectionFactory對象 --> <constructor-arg ref="mqConnectionFactory" /><!-- pub/sub模型(發布/訂閱) --><property name="pubSubDomain" value="true" /></bean><!--Spring JmsTemplate 的消息生產者 end--> </beans>maven的pom文件完整代碼:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>cn.niwotaxuexiba.maven</groupId><artifactId>common_parent</artifactId><version>0.0.1-SNAPSHOT</version></parent> <artifactId>bos_fore</artifactId><packaging>war</packaging><name>bos_fore</name><description>物流前端系統</description><build><plugins><plugin><groupId>org.codehaus.mojo</groupId><artifactId>tomcat-maven-plugin</artifactId><version>1.1</version><configuration><port>9003</port></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build><dependencies><dependency><groupId>cn.niwotaxuexiba.maven</groupId><artifactId>crm_domain</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies> </project>總結
以上是生活随笔為你收集整理的重构客户注册-基于ActiveMQ实现短信验证码生产者的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ActiveMQ入门案例-生产者代码实现
- 下一篇: jQuery EasyUI布局容器lay