SpringBoot整合RabbitMQ測試

2021-09-22 18:51:26 字數 1816 閱讀 2803

首先在生產者和消費者中都新增兩個依賴

org.springframework.boot

spring-boot-starter-amqp

org.springframework.boot

spring-boot-starter-test

server:

port: 44000

spring:

name: test-rabbitmq-producer

rabbitmq:

host: 127.0.0.1

port: 5672

username: guest

passowrd: guest

virtualhost: /

編寫生產者test-springboot-producer的配置類rabbitmqconfig

import org.springframework.amqp.core.*;

import org.springframework.beans.factory.annotation.qualifier;

import org.springframework.context.annotation.bean;

import org.springframework.context.annotation.configuration;

@configuration

public class rabbitmqconfig

@bean(queue_sms)

public queue queue_sms()

//宣告交換機

@bean(exchange_topic_inform)

public exchange exchange_topic_inform()

//佇列繫結交換機

@bean

public binding bind_queue_email(@qualifier(queue_email)queue queue,@qualifier(exchange_topic_inform)exchange exchange)

@bean

public binding bind_queue_sms(@qualifier(queue_sms)queue queue,@qualifier(exchange_topic_inform)exchange exchange)

}

編寫test-springboot-producer的啟動類

public static void main(string args)

}編寫消費者test-springboot-consummer的監聽類myconsummer

import org.springframework.amqp.rabbit.annotation.rabbitlistener;

import org.springframework.stereotype.component;

@component

public class myconsumer )

public void receiveemailmessage(string message)

@rabbitlistener(queues = )

public void receivesmsmessage(string message)

}

配置test-springboot-consummer的啟動類

public static void main(string args)

}這樣就整合完成了

SpringBoot使用訊息中介軟體RabbitMQ

首先在docker中安裝rabbitmq,pull 帶有web介面的 docker pull rabbitmq 3 management5672為客戶端,15672為web介面埠 docker run d p5672 5672 p15672 15672 name rabbitmq01 映象id簡要介...

springBoot整合dubbo整合專案

傳統spring 整合dubbo,需要繁瑣的編寫一堆堆的 xml 配置檔案 而springboot整合dubbo後,不在需要寫 xml,通過jar包引用,完 成整合,通過註解的形式完成配置。提高我們的開發效率 目錄結構 1 服務層生產者開發 hs ldm server service 1.1新增du...

SpringBoot整合系列 整合Swagger2

io.springfox springfox swagger2 2.7.0 io.springfox springfox swagger ui 2.7.0 一般無配置項,必要時可以新增自定義配置項,在配置類中讀取 swagger2的配置內容僅僅就是需要建立乙個docket例項 configurati...