content: package com.george.springcloud.service.impl;
  
  
  import com.george.springcloud.service.IMessageProvider;
  import lombok.extern.slf4j.Slf4j;
  import org.springframework.cloud.stream.annotation.EnableBinding;
  import org.springframework.cloud.stream.messaging.Source;
  import org.springframework.messaging.MessageChannel;
  import org.springframework.messaging.support.MessageBuilder;
  
  import javax.annotation.Resource;
  import java.util.UUID;
  
  /**
   * @author Yang Hao
   * @EnableBinding 注解是绑定channel和exchange绑定在一起
   * Source 定义消息的推送管道
   * 官网案例 https://cloud.spring.io/spring-cloud-static/spring-cloud-stream-binder-rabbit/3.0.1.RELEASE/reference/html/spring-cloud-stream-binder-rabbit.html
   * @date 2020-09-21 15:33
   */
  @EnableBinding(Source.class)
  @Slf4j
  public class MessageProviderImpl implements IMessageProvider {
  
      //消息发送管道
      @Resource
      private MessageChannel output;
  
      @Override
      public String send() {
          String serial = UUID.randomUUID().toString();
          output.send(MessageBuilder.withPayload(serial).build());
          log.info("生产者发送消息 ------> [{}]", serial);
          return null;
      }
  }
  