一、rabbitmq非同步訊息機制
1、exchange和queue進行繫結,乙個exchange可以繫結多個queue。
2、訊息生產者produce,將訊息傳送至exchange,exchange將訊息路由至多個queue。
3、exchange路由分為fanout、direct、topic三種模式。
4、消費者customer監聽相應的queue,接收訊息,觸發非同步方法。
二、springboot中的使用
1、引入依賴
org.springframework.boot
spring-boot-starter-amqp
2.2.5.release
spring.rabbitmq.virtual-host=lwt
spring.rabbitmq.host=127.0.0.1
spring.rabbitmq.port=5672
spring.rabbitmq.username=admin
spring.rabbitmq.password=admin
spring.rabbitmq.listener.******.concurrency=10
spring.rabbitmq.listener.******.max-concurrency=20
spring.rabbitmq.listener.******.prefetch=50
3、配置rabbitmq
@configuration
public
class
rabbitmqconfig
/** * 多個消費者
* @return
*/@bean
(name =
"multilistenercontainer"
)public ******rabbitlistenercontaine***ctory multilistenercontainer()
@bean
public rabbittemplate rabbittemplate()
),ack({}),cause({})"
,correlationdata,ack,cause);}
}); rabbittemplate.
setreturncallback
(new
rabbittemplate.returncallback()
),route({}),replycode({}),replytext({}),message:{}"
,exchange,routingkey,replycode,replytext,message);}
});return rabbittemplate;
}//todo:使用者註冊訊息模型
@bean
public queue userregisterqueue()
@bean
public exchange userregisterexchange()
@bean
public binding subcontractinvalidbinding()
3、訊息傳送
@autowired
private amqptemplate amqptemplate;
@autowired
(value =
"/hellosender"
,method = requestmethod.post)
public string hellosender
(@requestbody string message)
throws jsonprocessingexception
4、訊息接收
@component
public
class
rabbitmqlistener
",message);}
catch
(exception e)
}}
三、問題與注意事項
1、傳送字串型別的資料資訊時,反序列化報錯。
caused by: com.fasterxml.jackson.databind.exc.mismatchedinputexception: cannot deserialize instance of `[b` out of start_object token
at [source:
(string)
""; line:
1, column:
1]
MQ使用經驗總結
mq使用經驗總結 mq經驗總結 首先了解什麼是mq?mq的作用是什麼?mq是通訊中介軟體。他的作用是省去開發人員開發通訊工具的時間,節省開發成本,提高開發效 率。mq的使用,如何安裝mq?根據以往的經驗,win版的mq比較容易安裝,傻瓜式,一路next就可以。aix版本的用 itty安裝。linux...
MQ使用經驗總結
mq使用經驗總結 mq經驗總結 首先了解什麼是mq?mq的作用是什麼?mq是通訊中介軟體。他的作用是省去開發人員開發通訊工具的時間,節省開發成本,提高開發效 率。mq的使用,如何安裝mq?根據以往的經驗,win版的mq比較容易安裝,傻瓜式,一路next就可以。aix版本的用smitty安裝。linu...
MQ使用所得
建立的連線,在寫正常斷開連線終止程式時,可以通過在類的重寫destory 方法在時邊加上if null conn mq支援唯讀,取模式 mq佇列管理器有自己的連線池,可以使用連線池獲得連線 我們可以使用的mq自己的預設連線池,因為我的專案是每個執行緒訪問不同一的佇列管理器,所以我是在run 方法的開...