简体   繁体   English

Spring集成:无法将消息发送到频道

[英]Spring integration : Not able to send the message to channel

I am using spring-framework and spring-integration latest versions and just making POC application with spring integration but can't run this. 我正在使用spring-frameworkspring-integration最新版本,并且仅使POC应用程序具有spring集成功能,但是无法运行它。

I have spring integration confing something like this. 我有Spring Integration承认这样的事情。

    <bean id="initUrlQ" class="org.apache.activemq.command.ActiveMQQueue">
        <constructor-arg value="initUrl.Q" />
    </bean> 
   <int:channel id="initChannelProducerId" />

    <jms:outbound-channel-adapter id="initOutboundId" channel="initChannelProducerId" connection-factory="padtoys.jms.cachedConnectionFactory"
        destination="initUrlQ"  />
    <int:channel id="initChannelConsumerId" />
    <jms:message-driven-channel-adapter id="initQListenerId" channel="initChannelConsumerId"
        connection-factory="padtoys.jms.cachedConnectionFactory" destination="initUrlQ"
        acknowledge="auto" concurrent-consumers="1" max-concurrent-consumers="1" />  

    <int:service-activator method="testSA" ref="testBean" input-channel="initChannelConsumerId" output-channel="nullChannel"/>

And my testBean java file looks like this. 我的testBean java文件看起来像这样。

public class TestBean implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    @PostConstruct
    public void afterInit(){
        System.err.println("after init..!");
        DirectChannel inChannel = applicationContext.getBean("initChannelProducerId", DirectChannel.class);
        System.err.println("channel::" + inChannel);
        inChannel.send(createMessage("This is test url!!", 0));
    }

    @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    @ServiceActivator
    public String testSA(){
        System.err.println("inside service activator!!!");
        return "this is test";
    }

    private Message<String> createMessage(final String url, final int depth) {
        return MessageBuilder.withPayload(StringUtils.EMPTY)
                .setHeader(MESSAGE_HEADERS.URL, url)
                .setHeader(MESSAGE_HEADERS.DEPTH, depth).build();
    }
} 

And I am starting my application something like this. 我正在开始这样的应用程序。

@SuppressWarnings("resource") public static void main(String[] args) {
        LOG.info("Trigerring process!");
        new ClassPathXmlApplicationContext("/application-context.xml");
    }

Please consider that I have declared testBean and padtoys.jms.cachedConnectionFactory in spring context xml. 请考虑我已经在Spring上下文xml中声明了testBeanpadtoys.jms.cachedConnectionFactory

PROBLEM : 问题:

When I start the application, getting below error 当我启动应用程序时,出现以下错误

Caused by: org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'org.springframework.context.support.ClassPathXmlApplicationContext@5a1198c7.initChannelProducerId'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
        at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
        at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:423)
        at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:373)
        at com.dodax.pad.ext.toys.crawler.scanner.TestBean.afterInit(TestBean.java:25)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:366)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:311)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:134)
        ... 30 more
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
        at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:138)
        at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
        at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)

NOTE : 注意 :

I am getting right channel name at this line, System.err.println("channel::" + inChannel); 我在此行获得正确的频道名称, System.err.println("channel::" + inChannel); , but problem starts when I try to send the message to channel. ,但是当我尝试将消息发送到频道时问题开始了。

You must not perform messaging ( send() ) in a @PostConstruct method - it is too early in the application context lifecycle; 您不得在@PostConstruct方法中执行消息传递( send() )-这在应用程序上下文生命周期中为时过早; the context is not yet ready to perform messaging. 上下文尚未准备好执行消息传递。

See this answer for the proper place to perform messaging during startup. 请参阅此答案以获取在启动过程中执行消息传递的适当位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 集成:无法在超时内向通道“executionFilterChannel”发送消息:-1 - Spring integration : Failed to send message to channel 'executionFilterChannel' within timeout: -1 Spring-Integration-Kafka出站通道适配器发送消息 - Spring-Integration-Kafka outbound-channel-adapter Send message sftp spring集成无法在超时内将消息发送到通道:-1 - sftp spring integration failed to send message to channel within timeout: -1 spring集成消息驱动通道适配器 - spring integration message-driven-channel-adapter Spring Integration DSL,从消息通道轮询 - Spring Integration DSL, poll from message channel Spring Integration手动将消息发布到渠道 - Spring Integration manually publish message to channel 将消息从不同线程中的多个通道发送到Spring Integration中的单个通道 - Send message from multiple channels, in different threads, to a single channel in Spring Integration 使用 jms:inbound-channel-adapter 使用 spring 集成向发件人发送自定义确认消息 - Send Custom Acknowledgement message to sender using jms:inbound-channel-adapter using spring integration Spring Integration Kafka消息驱动通道适配器接收消息 - Spring Integration Kafka message-driven-channel-adapter receive message 如何使用 Spring Integration 发送 gcm xmpp 消息? - How to send a gcm xmpp message with Spring Integration?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM