Package org.springframework.integration

Examples of org.springframework.integration.MessageChannel


    @Test
    public void testSendingOneWayMessage() throws Exception {
        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
        resultEndpoint.expectedBodiesReceived(MESSAGE_BODY);

        MessageChannel outputChannel = (MessageChannel) applicationContext.getBean("outputChannel");
        outputChannel.send(new GenericMessage<Object>(MESSAGE_BODY));

        resultEndpoint.assertIsSatisfied();
    }
View Full Code Here


    @Test
    public void testSendingOneWayMessage() throws Exception {
        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
        resultEndpoint.expectedBodiesReceived(MESSAGE_BODY);
        MessageChannel outputChannel = (MessageChannel) applicationContext.getBean("channelA");
        outputChannel.send(new GenericMessage<Object>(MESSAGE_BODY));
        resultEndpoint.assertIsSatisfied();
    }
View Full Code Here

    }

    @Test
    public void testSendingTwoWayMessage() throws Exception {

        MessageChannel requestChannel = (MessageChannel) applicationContext.getBean("channelB");
        Message message = new GenericMessage<Object>(MESSAGE_BODY);
        //Need to subscribe the responseChannel first
        DirectChannel responseChannel = (DirectChannel) applicationContext.getBean("channelC");
        responseChannel.subscribe(new MessageHandler() {
            public void handleMessage(Message<?> message) {
                String result = (String) message.getPayload();
                assertEquals("Get the wrong result", MESSAGE_BODY + " is processed",  result);               
            }           
        });
        requestChannel.send(message);
    }
View Full Code Here

    }

    @Test
    public void testSendingTwoWayMessageWithMessageAddress() throws Exception {

        MessageChannel requestChannel = (MessageChannel) applicationContext.getBean("channelD");
        DirectChannel responseChannel = (DirectChannel) applicationContext.getBean("channelC");
        Map<String, Object> headers = new HashMap<String, Object>();
        headers.put(MessageHeaders.REPLY_CHANNEL, responseChannel);
        GenericMessage<String> message = new GenericMessage<String>(MESSAGE_BODY, headers);
        responseChannel.subscribe(new MessageHandler() {
            public void handleMessage(Message<?> message) {
                String result = (String) message.getPayload();
                assertEquals("Get the wrong result", MESSAGE_BODY + " is processed",  result);               
            }           
        });
        requestChannel.send(message);       
    }
View Full Code Here

    @Test
    public void testSendingOneWayMessage() throws Exception {
        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
        resultEndpoint.expectedBodiesReceived(MESSAGE_BODY);
        MessageChannel outputChannel = applicationContext.getBean("channelA", MessageChannel.class);
        outputChannel.send(new GenericMessage<Object>(MESSAGE_BODY));
        resultEndpoint.assertIsSatisfied();
    }
View Full Code Here

    }

    @Test
    public void testSendingTwoWayMessage() throws Exception {

        MessageChannel requestChannel = applicationContext.getBean("channelB", MessageChannel.class);
        Message<?> message = new GenericMessage<Object>(MESSAGE_BODY);
        //Need to subscribe the responseChannel first
        DirectChannel responseChannel = (DirectChannel) applicationContext.getBean("channelC");
        responseChannel.subscribe(new MessageHandler() {
            public void handleMessage(Message<?> message) {
                String result = (String) message.getPayload();
                assertEquals("Get the wrong result", MESSAGE_BODY + " is processed",  result);               
            }           
        });
        requestChannel.send(message);
    }
View Full Code Here

    }

    @Test
    public void testSendingTwoWayMessageWithMessageAddress() throws Exception {

        MessageChannel requestChannel = applicationContext.getBean("channelD", MessageChannel.class);
        DirectChannel responseChannel = applicationContext.getBean("channelC", DirectChannel.class);
        Map<String, Object> headers = new HashMap<String, Object>();
        headers.put(MessageHeaders.REPLY_CHANNEL, responseChannel);
        GenericMessage<String> message = new GenericMessage<String>(MESSAGE_BODY, headers);
        responseChannel.subscribe(new MessageHandler() {
            public void handleMessage(Message<?> message) {
                String result = (String) message.getPayload();
                assertEquals("Get the wrong result", MESSAGE_BODY + " is processed",  result);               
            }           
        });
        requestChannel.send(message);       
    }
View Full Code Here

            return;
        }

        // reply logic
        if (getEndpoint().isInOut()) {
            MessageChannel reply = null;

            // get the output channel from message header
            Object returnAddress = siInMessage.getHeaders().getReplyChannel();
            if (returnAddress != null) {
                if (returnAddress instanceof String) {
                    reply = context.getApplicationContext().getBean((String)returnAddress, MessageChannel.class);
                } else if (returnAddress instanceof MessageChannel) {
                    reply = (MessageChannel) returnAddress;
                }
            } else {
                reply = outputChannel;

                // we want to do in-out so the inputChannel is mandatory (used to receive reply from spring integration)
                if (reply == null) {
                    throw new IllegalArgumentException("OutputChannel has not been configured on " + getEndpoint());
                }
            }

            if (reply == null) {
                throw new IllegalArgumentException("Cannot resolve ReplyChannel from message: " + siInMessage);
            }

            // put the message back the outputChannel if we need
            org.springframework.integration.Message<?> siOutMessage =
                SpringIntegrationBinding.storeToSpringIntegrationMessage(exchange.getOut());

            // send the message to spring integration
            log.debug("Sending {} to ReplyChannel: {}", siOutMessage, reply);
            reply.send(siOutMessage);
        }       
    }  
View Full Code Here

    private static final String MESSAGE_BODY = "Request message";

    @Test
    public void testSendingTwoWayMessage() throws Exception {
        final CountDownLatch latch = new CountDownLatch(1);
        MessageChannel requestChannel = getMandatoryBean(MessageChannel.class, "requestChannel");
        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put(MessageHeaders.REPLY_CHANNEL, "responseChannel");
        Message<String> message = new GenericMessage<String>(MESSAGE_BODY, maps);

        DirectChannel responseChannel = getMandatoryBean(DirectChannel.class, "responseChannel");
        responseChannel.subscribe(new MessageHandler() {
            public void handleMessage(Message<?> message) {
                latch.countDown();
                assertEquals("Get the wrong result", MESSAGE_BODY + " is processed",  message.getPayload());
                assertEquals("Done",  message.getHeaders().get("Status"));
            }            
        });

        requestChannel.send(message);

        assertTrue(latch.await(1, TimeUnit.SECONDS));
    }
View Full Code Here

        } while (ctx.containsBean(beanId));

        beanFactory.registerBeanDefinition(beanId, beanDefinition);
        ServiceActivatingHandler _serviceActivatingHandler = ctx.getBean(beanId, ServiceActivatingHandler.class);

        MessageChannel bridgeChannel = null;
        SubscribableChannel channel = null;
        String channelName =
                (
                        listener.getNamespace() != null &&
                                !listener.getNamespace().equalsIgnoreCase(APP_NAMESPACE) ? listener.getNamespace() + "://" : ""
                )
                        + listener.getTopic();


        try {
            bridgeChannel = ctx.getBean(channelName, MessageChannel.class);

            if (!GrailsPublishSubscribeChannel.class.isAssignableFrom(bridgeChannel.getClass())) {
                channel = findOrCreateChannel(channelName + "-local", listener);

                if (autoBridge  && bridgeChannel.getClass().isAssignableFrom(SubscribableChannel.class)) {
                    BridgeHandler bridgeHandler = new BridgeHandler(channelName);
                    bridgeHandler.setOutputChannel(channel);
                    ((SubscribableChannel) bridgeChannel).subscribe(bridgeHandler);
                }
View Full Code Here

TOP

Related Classes of org.springframework.integration.MessageChannel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.