栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

SpringCloud-SpringCloud Stream消息驱动之消息消费者(Day10)

SpringCloud-SpringCloud Stream消息驱动之消息消费者(Day10)

创建消息消费模块cloud-stream-rabbitmq-consumer8802



更改消费模块的pom


    
        cloud2022
        org.gcl.learn
        1.0-SNAPSHOT
    
    4.0.0

    cloud-stream-rabbitmq-consumer8802

    
        
            org.springframework.cloud
            spring-cloud-starter-stream-rabbit
        

        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        

        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-actuator
        

        
            org.springframework.boot
            spring-boot-devtools
            runtime
            true
        

        
            org.projectlombok
            lombok
            true
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
            junit
            junit
            test
        
    


更改消费模块的yml
server:
  port: 8802

spring:
  application:
    name: cloud-stream-rabbitmq-consumer
  rabbitmq:
    host: xxx.xx.xx.xx
    port: 5672
    username: guest
    password: guest
  cloud:
    stream:
      binders:
        defaultRabbit:
          type: rabbit
      bindings:
        input:
          destination: studyExchange
          content-type: application/json
          binder: defaultRabbit
eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:7001/eureka
    register-with-eureka: true
    fetch-registry: true
更改消费模块的主启动类
package com.gcl.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@EnableEurekaClient
@SpringBootApplication
public class StreamRabbitMQMain8802 {

    public static void main(String[] args) {
        SpringApplication.run( StreamRabbitMQMain8802.class , args );
    }

}
更改消费模块的业务类
package com.gcl.springcloud.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

@Component
@EnableBinding(Sink.class)
public class StreamRabbitMQService {

    @Value("${server.port}")
    private String serverPort;

    @StreamListener(Sink.INPUT)
    public void input(Message message){
        System.out.println("***************接收到的消息:" + message.getPayload() + " server.port : " + serverPort );
    }

}
运行




转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/672275.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号