【问题标题】:Is there any way to send empty payload message using spring integration gateway?有没有办法使用弹簧集成网关发送空有效负载消息?
【发布时间】:2016-11-25 01:40:21
【问题描述】:

我正在尝试使用 spring 集成 AMQP 进行 RPC,我有一个方法在我的网关中不接受任何参数,但是当我调用它时消息不会发送到我的交换机。

@MessagingGateway
public interface StatusGateway {
    boolean getStatus();
}

这里是我的 integration-context.xml

<rabbit:connection-factory id="rabbitConnectionFactory" 
    host="172.17.0.2" virtual-host="/myvhost" 
    username="myuser" password="mypasswd" />

<rabbit:template id="default" connection-factory="rabbitConnectionFactory" />
<rabbit:topic-exchange name="slr-input" auto-declare="false" />

<int:gateway id="statusGateway"
    service-interface="com.example.StatusGateway"
    default-request-channel="requestChannel"
    default-reply-channel="replyChannel" />

<int:channel id="requestChannel" />
<int:channel id="replyChannel" />

<int-amqp:outbound-gateway id="statusRequestGateway"
    amqp-template="default"
    exchange-name="slr-input"
    routing-key="operation.status"
    request-channel="requestChannel"
    reply-channel="replyChannel"
    lazy-connect="true" />

当我调用 getStatus 方法时,我得到以下异常

java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:803) [spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:784) [spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]
    at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:771) [spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]
    at com.example.AmqpTestClientApplication.main(AmqpTestClientApplication.java:14) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_91]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_91]
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) [idea_rt.jar:na]
Caused by: java.lang.IllegalStateException: receive is not supported, because no pollable reply channel has been configured
    at org.springframework.util.Assert.state(Assert.java:392) ~[spring-core-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.integration.gateway.MessagingGatewaySupport.receive(MessagingGatewaySupport.java:380) ~[spring-integration-core-4.2.8.RELEASE.jar:na]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:416) ~[spring-integration-core-4.2.8.RELEASE.jar:na]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:382) ~[spring-integration-core-4.2.8.RELEASE.jar:na]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:373) ~[spring-integration-core-4.2.8.RELEASE.jar:na]
    at org.springframework.integration.gateway.GatewayCompletableFutureProxyFactoryBean.invoke(GatewayCompletableFutureProxyFactoryBean.java:64) ~[spring-integration-core-4.2.8.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at com.sun.proxy.$Proxy44.getStatus(Unknown Source) ~[na:na]
    at com.example.AmqpTestClientApplication.lambda$commandLineRunner$0(AmqpTestClientApplication.java:20) [classes/:na]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:800) [spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]

有人知道如何在不发送非空消息的情况下发出请求吗?

【问题讨论】:

    标签: java spring rabbitmq spring-integration


    【解决方案1】:

    不带参数的网关方法默认是接收操作;见Messaging Gateway: Invoking No-Argument Methods

    您可以使用类似将default-payload-expression="''" 添加到网关(一个空字符串)。

    【讨论】:

    • 嗨,Gary,我没有创建标签的权限,但你可以为我没有找到的 spring-integration-amqp 创建一个标签。
    • 我们不需要为每个 spring-integration 模块添加标签;只需使用 spring-integration - 您也可以添加 spring-amqp 标签,但这个问题与 amqp/rabbitmq 无关。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多