RabbitMQ 上的 Spring 集成和 AMQP 抛出异常 Method handleToken(byte[]) 找不到

标签 spring rabbitmq spring-integration spring-amqp

这是我的上下文配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
       xmlns:rabbit="http://www.springframework.org/schema/rabbit"
       xmlns:int="http://www.springframework.org/schema/integration"
       xsi:schemaLocation="http://www.springframework.org/schema/integration/amqp   http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
                http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">


    <rabbit:connection-factory id="connectionFactory" host="localhost"/>

    <rabbit:template id="amqpTemplate" connection-factory="connectionFactory"/>

    <rabbit:queue name="upload-queue"/>


    <rabbit:admin connection-factory="connectionFactory"/>

    <rabbit:topic-exchange name="infrastructure-exchange">
        <rabbit:bindings>
            <rabbit:binding queue="upload-queue" pattern="ru.interosite.*"/>
        </rabbit:bindings>
    </rabbit:topic-exchange>


    <int-amqp:outbound-channel-adapter
            channel="toRabbit"
            routing-key="ru.interosite.1"
            amqp-template="amqpTemplate"
            exchange-name="infrastructure-exchange"/>

    <int-amqp:inbound-channel-adapter
            channel="fromRabbit"
            queue-names="upload-queue"
            connection-factory="connectionFactory"
            />


    <int:gateway id="infrastructureGateway" service-interface="com.dropbyke.web.api.service.InfrastructureGateway"/>

    <int:channel id="toRabbit"/>
    <int:channel id="fromRabbit"/>


    <bean id="testInfrastructureServiceImpl" class="com.dropbyke.web.api.service.TestInfrastructureServiceImpl"/>

    <int:service-activator input-channel="fromRabbit" ref="testInfrastructureServiceImpl" method="handleToken" />

    <!-- A Spring Integration adapter that routes messages sent to the helloWorldChannel to the bean named "helloServiceImpl"'s hello() method -->
    <!--<int:outbound-channel-adapter channel="fromRabbit" ref="testInfrastructureServiceImpl" method="handleToken"/>-->


</beans>

这是网关接口(interface):

public interface InfrastructureGateway {

    @Gateway(requestChannel = "toRabbit")
    void doUpload(UserTokenDTO tokenDTO);

}

应该处理调用的消息端点:

@MessageEndpoint
public class TestInfrastructureServiceImpl implements TestInfrastructureService {

    public void handleToken( UserTokenDTO tokenDTO) {
        System.out.println("Handle user token " + tokenDTO.getToken());

    }

}

因此,当我调用网关的 doUpload 方法时,我收到此错误消息:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 8): Method call: Method handleToken(byte[]) cannot be found on com.dropbyke.web.api.service.TestInfrastructureServiceImpl type

如果我排除兔子部分,那么一切正常。我应该怎么做才能让它与 Rabbit 一起工作?我应该实现一些从 byte[] 到我的域对象 UserTokenDTO 的转换器吗?

最佳答案

正如 nicolas-labrot 建议的那样,我必须使我的 UserTokenDTO 成为可序列化的。之后一切正常。

关于RabbitMQ 上的 Spring 集成和 AMQP 抛出异常 Method handleToken(byte[]) 找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29567260/

相关文章:

java - 防止 Controller 响应

rabbitmq - 如何重启RabbitMQ服务

rabbitmq - 为 RabbitMQ ack 消息设置较长的超时

spring-integration - Spring云流从kinesis收到的消息中的特殊字符

java - 如何从 Spring 集成中完成重新排序器中的分组

java - Spring 不归档属性文件

java - 即使无法联系发现服务器,是否有办法启动 Discovery 客户端 Spring 应用程序?

java - 无法使用 java.sql.Date 返回 List<Object>?

java - Spring RabbitMQ 将新队列附加到现有监听器

java - 我需要当前易于遵循的说明来从 XML 配置 spring 集成 kafka