Package org.springframework.messaging

Examples of org.springframework.messaging.MessageChannel


   * Test method for {@link org.springframework.integration.samples.ftp.DynamicFtpChannelResolver#resolve(java.lang.String)}.
   */
  @Test
  public void testResolve() {
    DynamicFtpChannelResolver dynamicFtpChannelResolver = new DynamicFtpChannelResolver();
    MessageChannel channel1 = dynamicFtpChannelResolver.resolve("customer1");
    assertNotNull(channel1);
    MessageChannel channel2 = dynamicFtpChannelResolver.resolve("customer2");
    assertNotNull(channel2);
    assertNotSame(channel1, channel2);
    MessageChannel channel1a = dynamicFtpChannelResolver.resolve("customer1");
    assertSame(channel1, channel1a);
  }
View Full Code Here


  @Test
  public void runDemo() throws Exception{
    ConfigurableApplicationContext ctx =
      new ClassPathXmlApplicationContext("META-INF/spring/integration/DynamicFtpOutboundChannelAdapterSample-context.xml");
    MessageChannel channel = ctx.getBean("toDynRouter", MessageChannel.class);
    File file = File.createTempFile("temp", "txt");
    Message<File> message = MessageBuilder.withPayload(file)
            .setHeader("customer", "cust1")
            .build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust1"));
    }
    // send another so we can see in the log we don't create the ac again.
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust1"));
    }
    // send to a different customer; again, check the log to see a new ac is built
    message = MessageBuilder.withPayload(file)
        .setHeader("customer", "cust2").build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust2"));
    }

    // send to a different customer; again, check the log to see a new ac is built
    //and the first one created (cust1) should be closed and removed as per the max cache size restriction
    message = MessageBuilder.withPayload(file)
        .setHeader("customer", "cust3").build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust3"));
    }

    //send to cust1 again, since this one has been invalidated before, we should
    //see a new ac created (with ac of cust2 destroyed and removed)
    message = MessageBuilder.withPayload(file)
        .setHeader("customer", "cust1").build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertEquals("host.for.cust1", e.getCause().getCause().getCause().getMessage());
    }
View Full Code Here

  @Test
  public void runDemo() throws Exception{
    ApplicationContext context =
      new ClassPathXmlApplicationContext("META-INF/spring/integration/TwitterSendUpdates-context.xml");
   
    MessageChannel twitterOutChannel = context.getBean("twitterOut", MessageChannel.class);
    Message<String> twitterUpdate = new GenericMessage<String>("Testing new Twitter samples for #springintegration");
    twitterOutChannel.send(twitterUpdate);
  }
View Full Code Here

  public static void main(String[] args) throws Exception {
    AbstractApplicationContext applicationContext =
      new ClassPathXmlApplicationContext("/META-INF/spring/integration/orderProcessingSample.xml",
        BookOrderProcessingTestApp.class);
    MessageChannel messageChannel = (MessageChannel) applicationContext.getBean("ordersChannel");
    GenericMessage<Document> orderMessage =
      createXmlMessageFromResource("META-INF/spring/integration/order.xml");
    messageChannel.send(orderMessage);
    applicationContext.close();
  }
View Full Code Here

      final File file = new File(sourceFileName);

      Assert.isTrue(file.exists(), String.format("File '%s' does not exist.", sourceFileName));

      final Message<File> message = MessageBuilder.withPayload(file).build();
      final MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);

      inputChannel.send(message);
      Thread.sleep(2000);

      Assert.isTrue(SftpTestUtils.fileExists(template, destinationFileName));

      System.out.println(String.format("Successfully transferred '%s' file to a " +
View Full Code Here

    // Create the Message object
    Message<String> message = MessageBuilder.withPayload(requestXml).build();

    // Send the Message to the handler's input channel
    MessageChannel channel = channelResolver.resolveDestination("fahrenheitChannel");
    channel.send(message);
  }
View Full Code Here

    System.setProperty("spring.profiles.active", "testCase");

    final GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(configFilesGatewayDemo);

    final MessageChannel stdinToJmsoutChannel = applicationContext.getBean("stdinToJmsoutChannel", MessageChannel.class);

    stdinToJmsoutChannel.send(MessageBuilder.withPayload("jms test").build());

    final QueueChannel queueChannel = applicationContext.getBean("queueChannel", QueueChannel.class);

    @SuppressWarnings("unchecked")
    Message<String> reply = (Message<String>) queueChannel.receive(20000);
View Full Code Here

    System.setProperty("spring.profiles.active", "testCase");

    final GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(configFilesChannelAdapterDemo);

    final MessageChannel stdinToJmsoutChannel = applicationContext.getBean("stdinToJmsoutChannel", MessageChannel.class);

    stdinToJmsoutChannel.send(MessageBuilder.withPayload("jms test").build());

    final QueueChannel queueChannel = applicationContext.getBean("queueChannel", QueueChannel.class);

    @SuppressWarnings("unchecked")
    Message<String> reply = (Message<String>) queueChannel.receive(20000);
View Full Code Here

  @Test
  public void demoControlBus(){
    ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext(
        "/META-INF/spring/integration/ControlBusDemo-context.xml");
    MessageChannel controlChannel = ac.getBean("controlChannel", MessageChannel.class);
    PollableChannel adapterOutputChanel = ac.getBean("adapterOutputChanel", PollableChannel.class);
    logger.info("Received before adapter started: " + adapterOutputChanel.receive(1000));
    controlChannel.send(new GenericMessage<String>("@inboundAdapter.start()"));
    logger.info("Received before adapter started: " + adapterOutputChanel.receive(1000));
    controlChannel.send(new GenericMessage<String>("@inboundAdapter.stop()"));
    logger.info("Received after adapter stopped: " + adapterOutputChanel.receive(1000));
    ac.close();
  }
View Full Code Here

   *
   * @param customer
   * @return a channel
   */
  public MessageChannel resolve(String customer) {
    MessageChannel channel = this.channels.get(customer);
    if (channel == null) {
      channel = createNewCustomerChannel(customer);
    }
    return channel;
  }
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.