RocketMQメッセージ駆動型エントリの春クラウドストリーム(A)

SpringCloudStream現在サポートされているミドルウェアはRabbitMQの、カフカがあり、私の最近のRocketMQの研究は、以下が私の研究ノートで
春クラウドストリームは、最初のおよそ春メッセージングと春の統合を理解して学ぶことができる学習、

モデル春メッセージメッセージを見てみましょう

ファイル

メッセージ本体およびメッセージ・ヘッダのペイロードヘッダを含むメッセージング対応するモデル

ファイル

メッセージチャネル、ラインにメッセージを送信し、デモ、それを指示することができるsendメソッドを呼び出して、メッセージを受信するためのMessageChannelメッセージチャンネル

pom.xml依存性

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>cloud-stream-rocketmq-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>cloud-stream-rocketmq-demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-rocketmq</artifactId>
            <version>0.2.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

@EnableBinding:このアノテーションは、メッセージチャネル(チャネル)の結合を達成するために、一つ以上の定義されたインタフェース@Input又は@outputアノテーションを指定するために使用され
@StreamListener:これは主に、注釈方法で定義されている、となりますデータ・ストリーム・ミドルウェア・メッセージ・イベントリスナ、注釈メッセージ聴取チャネル名に対応する属性値を変更するための方法として登録

@Component
@EnableBinding(StreamInput.class)
@Slf4j
public class ReceiveClient {

    @StreamListener(StreamInput.input)
    public void receive01(String message){
        log.info("接收消息:"+message);
    }


}

注釈@Inputチャンネルという名前の入力を拘束

public interface StreamInput {

    String input = "input";

    @Input(StreamInput.input)
    SubscribableChannel input();
}

チャネルと呼ばれる出力の結合注釈@output

public interface StreamInput {

    String input = "input";

    @Input(StreamInput.input)
    SubscribableChannel input();
}

試験
だけ追加した2つのインタフェースを持つ起動クラス
@EnableBinding({StreamInput.class、StreamOutput.class})

@Autowired
    private StreamOutput streamOutput;

    @GetMapping("/send")
    public String send(){
        MessageBuilder builder = MessageBuilder.withPayload("测试消息".getBytes());
        streamOutput.output().send(builder.build());
        return "ok";
    }

@EnableBindingバインディングコメントすることを忘れないでください

個人の連絡先QQ:944484545、学習を共有するために、参加することを歓迎は幸せなことです

おすすめ

転載: www.cnblogs.com/hy-xiaobin/p/12173233.html