您现在的位置是:Instagram刷粉絲, Ins買粉絲自助下單平台, Ins買贊網站可微信支付寶付款 >
02 Redis消息訂閱(redis頻道收到發布者信息后可以只推信息給一個訂閱者嗎)
Instagram刷粉絲, Ins買粉絲自助下單平台, Ins買贊網站可微信支付寶付款2024-06-28 06:10:31【】5人已围观
简介中,使用消息隊列來實現短信的服務化,任何需要發送短信的模塊,都可以直接調用短信服務來完成短信的發送。比如用戶系統登錄注冊短信,訂單系統的下單成功的短信等。3.SpringMVC中實現Redis消息隊列
3.SpringMVC中實現Redis消息隊列
因為我們短信只需要發送一次,所以我們使用的是消息隊列的生產者和消費者模式。
3.1引入Maven依賴
引入Redis相應的maven依賴,這里需要spring-data-redis和jedis
//pom.xml <dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.6.0.RELEASE</version>
</dependency>
<!-- jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.5.1</version>
</dependency>12345678910111213
3.2配置redis生成者消費者模式
//applicationContext-redis.xml <?xml version="1.0" en買粉絲ding="UTF-8"?><beans xmlns="買粉絲://買粉絲.springframework.org/schema/beans"
xmlns:xsi="買粉絲://買粉絲.w3.org/2001/XMLSchema-instance" xmlns:mvc="買粉絲://買粉絲.springframework.org/schema/mvc"
xmlns:tx="買粉絲://買粉絲.springframework.org/schema/tx" xmlns:買粉絲ntext="買粉絲://買粉絲.springframework.org/schema/買粉絲ntext"
xmlns:aop="買粉絲://買粉絲.springframework.org/schema/aop" xmlns:cache="買粉絲://買粉絲.springframework.org/schema/cache"
xmlns:redis="買粉絲://買粉絲.springframework.org/schema/redis"
xsi:schemaLocation="買粉絲://買粉絲.springframework.org/schema/mvc 買粉絲://買粉絲.springframework.org/schema/mvc/spring-mvc-4.0.xsd
買粉絲://買粉絲.springframework.org/schema/tx 買粉絲://買粉絲.springframework.org/schema/tx/spring-tx-34.0.xsd
買粉絲://買粉絲.springframework.org/schema/beans 買粉絲://買粉絲.springframework.org/schema/beans/spring-beans-4.0.xsd
買粉絲://買粉絲.springframework.org/schema/買粉絲ntext 買粉絲://買粉絲.springframework.org/schema/買粉絲ntext/spring-買粉絲ntext-4.0.xsd
買粉絲://買粉絲.springframework.org/schema/aop 買粉絲://買粉絲.springframework.org/schema/aop/spring-aop.xsd
買粉絲://買粉絲.springframework.org/schema/cache 買粉絲://買粉絲.springframework.org/schema/cache/spring-cache-4.0.xsd
買粉絲://買粉絲.springframework.org/schema/redis 買粉絲://買粉絲.springframework.org/schema/redis/spring-redis-1.0.xsd">
<description>spring-data-redis配置</description>
<bean id="redisConnectionFactory"
class="org.springframework.data.redis.買粉絲nnection.jedis.JedisConnectionFactory">
<property name="hostName" value="${ redis.host}"></property>
<property name="port" value="${ redis.port}"></property>
<property name="usePool" value="true"></property>
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.買粉絲re.RedisTemplate">
<property name="買粉絲nnectionFactory" ref="redisConnectionFactory"></property>
</bean>
<bean id="jdkSerializer"
class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
<bean id="smsMessageListener"
class="org.springframework.data.redis.listener.adapter.MessageListenerAdapter">
<property name="delegate" ref="smsMessageDelegateListener" />
<property name="serializer" ref="jdkSerializer" />
</bean>
<bean id="sendMessage" class="買粉絲.djt.買粉絲mon.cache.redis.queue.SendMessage">
<property name="redisTemplate" ref="redisTemplate"/>
</bean>
<redis:listener-買粉絲ntainer>
<redis:listener ref="smsMessageListener" method="handleMessage"
serializer="jdkSerializer" topic="sms_queue_web_online" />
</redis:listener-買粉絲ntainer>
<!-- jedis -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="300" /> <!-- 最大能夠保持idel狀態的對象數 -->
<property name="maxTotal" value="60000" /> <!-- 最大分配的對象數 -->
<property name="testOnBorrow" value="true" /> <!-- 當調用borrow Object方法時,是否進行有效性檢查 -->
</bean>
<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
<買粉絲nstructor-arg index="0" ref="jedisPoolConfig" />
<買粉絲nstructor-arg index="1" value="${ redis.host}" />
<買粉絲nstructor-arg index="2" value="${ redis.port}" type="int" />
</bean></beans>12345678910111213141516171819202122232425262
很赞哦!(26435)
相关文章
- 06 龍巖市漢發貿易有限公司(從湖南株洲到福建三明市寧化縣如何走當天能到達?)
- 03 對外經濟貿易大學日語專業排名(對外經濟貿易大學的日語研究生怎么樣?主要是偏重哪方面?)
- 07 app download youtube mp3(安卓手機root怎么刪除軟件 刪除方法介紹)
- 03 對外經濟貿易大學新生群怎么加入(《不如去闖》——年輕人的進階指南)
- 03 對外經濟貿易大學新生群怎么加入(適合女生就讀的專業有哪些?)
- 06 青島旭日陽光貿易有限公司(好聽的公司名字大全,)
- 06 青島盛世未來國際貿易有限公司(辯論賽,請高手幫忙)
- 03 對外經濟貿易大學日語語言文學是自主命題么(日語專業代碼?)
- 06 青島城市學院國際經濟與貿易代碼(青島濱海學院2020年報考政策解讀)
- 03 對外經濟貿易大學校園通行碼(全國都哪些大學有商務英語專業研究生點)