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

时间:2015-04-10 17:23:30

标签: 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>

这是网关接口:

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部分,那么一切正常。我该怎么做才能让它与Rabbit一起使用?我应该从byte[]到我的域对象UserTokenDTO实现一些转换器吗?

1 个答案:

答案 0 :(得分:0)

正如nicolas-labrot所说,我必须让我的UserTokenDTO成为Serializable。之后一切正常。