Package org.springframework.messaging

Examples of org.springframework.messaging.MessageChannel


  private static Logger logger = Logger.getLogger(HelloWorldApp.class);

  public static void main(String[] args) {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/helloWorldDemo.xml", HelloWorldApp.class);
    MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);
    PollableChannel outputChannel = context.getBean("outputChannel", PollableChannel.class);
    inputChannel.send(new GenericMessage<String>("World"));
    logger.info("==> HelloWorldDemo: " + outputChannel.receive(0).getPayload());
  }
View Full Code Here


    }
    return channel;
  }

  private synchronized MessageChannel createNewCustomerChannel(String customer) {
    MessageChannel channel = this.channels.get(customer);
    if (channel == null) {
      ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
          new String[] { "/META-INF/spring/integration/dynamic-ftp-outbound-adapter-context.xml" },
          false);
      this.setEnvironmentForCustomer(ctx, customer);
View Full Code Here

  public void runDemo() throws Exception{

    ConfigurableApplicationContext ctx =
      new ClassPathXmlApplicationContext("META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml");

    MessageChannel ftpChannel = ctx.getBean("ftpChannel", MessageChannel.class);

    baseFolder.mkdirs();

    final File fileToSendA = new File(baseFolder, "a.txt");
    final File fileToSendB = new File(baseFolder, "b.txt");

    final InputStream inputStreamA = FtpOutboundChannelAdapterSample.class.getResourceAsStream("/test-files/a.txt");
    final InputStream inputStreamB = FtpOutboundChannelAdapterSample.class.getResourceAsStream("/test-files/b.txt");

    FileUtils.copyInputStreamToFile(inputStreamA, fileToSendA);
    FileUtils.copyInputStreamToFile(inputStreamB, fileToSendB);

    assertTrue(fileToSendA.exists());
    assertTrue(fileToSendB.exists());

    final Message<File> messageA = MessageBuilder.withPayload(fileToSendA).build();
    final Message<File> messageB = MessageBuilder.withPayload(fileToSendB).build();

    ftpChannel.send(messageA);
    ftpChannel.send(messageB);

    Thread.sleep(2000);

    assertTrue(new File(TestSuite.FTP_ROOT_DIR + File.separator + "a.txt").exists());
    assertTrue(new File(TestSuite.FTP_ROOT_DIR + File.separator + "b.txt").exists());
View Full Code Here

  @Test
  public void runDemo() throws Exception{
    ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/integration/SendInstantMessageSample-context.xml");
   
    MessageChannel toUserChannel = context.getBean("toUserChannel", MessageChannel.class);
    Message<String> message = new GenericMessage<String>("Hello from Spring Integration XMPP");
    toUserChannel.send(message);
  }
View Full Code Here

    Runnable runnable = Mockito.mock(Runnable.class);
    SimpAttributes simpAttributes = new SimpAttributes(this.session.getId(), this.session.getAttributes());
    simpAttributes.setAttribute("name", "value");
    simpAttributes.registerDestructionCallback("name", runnable);

    MessageChannel testChannel = new MessageChannel() {
      @Override
      public boolean send(Message<?> message) {
        SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes();
        assertThat(simpAttributes.getAttribute("name"), is("value"));
        return true;
View Full Code Here

  @Test
  public void test() {

    SubscribableChannel clientInboundChannel = new StubMessageChannel();
    MessageChannel clientOutboundChannel = new StubMessageChannel();
    SubscribableChannel brokerChannel = new StubMessageChannel();

    String[] destinationPrefixes = new String[] { "/foo", "/bar" };

    StompBrokerRelayRegistration registration = new StompBrokerRelayRegistration(
View Full Code Here

    SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor);
    channel.subscribe(new MessageHandler() {
      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
        replyChannel.send(new GenericMessage<String>("response"));
      }
    });

    String actual = this.template.convertSendAndReceive(channel, "request", String.class);
    assertEquals("response", actual);
View Full Code Here

    channel.subscribe(new MessageHandler() {
      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        try {
          Thread.sleep(500);
          MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
          replyChannel.send(new GenericMessage<String>("response"));
          failure.set(new IllegalStateException("Expected exception"));
        }
        catch (InterruptedException e) {
          failure.set(e);
        }
View Full Code Here

    }

    @Override
    public Message receive(String selector, TestContext context, long timeout) {
        String destinationChannelName;
        MessageChannel destinationChannel = getDestinationChannel();

        if (StringUtils.hasText(selector)) {
            destinationChannelName = getDestinationChannelName() + "(" + selector + ")";
        } else {
            destinationChannelName = getDestinationChannelName();
        }

        log.info("Receiving message from: " + destinationChannelName);

        Message message;
        if (StringUtils.hasText(selector)) {
            if (!(destinationChannel instanceof MessageSelectingQueueChannel)) {
                throw new CitrusRuntimeException("Message channel type '" + endpointConfiguration.getChannel().getClass() +
                        "' does not support selective receive operations.");
            }

            MessageSelector messageSelector = new DispatchingMessageSelector(selector, endpointConfiguration.getBeanFactory());
            MessageSelectingQueueChannel queueChannel = ((MessageSelectingQueueChannel) destinationChannel);

            if (timeout <= 0) {
                message = endpointConfiguration.getMessageConverter().convertInbound(queueChannel.receive(messageSelector), endpointConfiguration);
            } else {
                message = endpointConfiguration.getMessageConverter().convertInbound(queueChannel.receive(messageSelector, timeout), endpointConfiguration);
            }
        } else {
            if (!(destinationChannel instanceof PollableChannel)) {
                throw new CitrusRuntimeException("Invalid destination channel type " + destinationChannel.getClass().getName() +
                        " - must be of type PollableChannel");
            }

            endpointConfiguration.getMessagingTemplate().setReceiveTimeout(timeout);
            message = endpointConfiguration.getMessageConverter().convertInbound(
View Full Code Here

    @Override
    public void send(Message message, TestContext context) {
        Assert.notNull(message, "Can not send empty message");

        String correlationKey = context.getCorrelationKey(this);
        MessageChannel replyChannel = findReplyChannel(correlationKey);
        Assert.notNull(replyChannel, "Failed to find reply channel for message correlation key: " + correlationKey);

        log.info("Sending message to reply channel: '" + replyChannel + "'");

        if (log.isDebugEnabled()) {
View Full Code Here

TOP

Related Classes of org.springframework.messaging.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.