Package org.springframework.messaging

Examples of org.springframework.messaging.MessageChannel


  @Test
  public void testWritingDataset() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
        "org/springframework/xd/integration/hadoop/config/DatasetOutboundChannelAdapterIntegrationTests.xml");
    MessageChannel channel = context.getBean("datasetOut", MessageChannel.class);
    channel.send(MessageBuilder.withPayload("foo").build());
    channel.send(MessageBuilder.withPayload("bar").build());
    DatasetOperations datasetOperations = context.getBean("datasetOperations", DatasetOperations.class);
    String path = context.getBean("path", String.class);
    assertTrue("Dataset path created", new File(path).exists());
    assertTrue("Dataset storage created",
        new File(path + "/" + "test/" + datasetOperations.getDatasetName(String.class)).exists());
View Full Code Here


    }
    return (Table) commandResult.getResult();
  }

  private void bindJobTap(String jobName) {
    MessageChannel alreadyBound = jobTapChannels.putIfAbsent(jobName, new QueueChannel());
    if (alreadyBound == null) {
      getMessageBus().bindPubSubConsumer("tap:job:" + jobName, jobTapChannels.get(jobName), null);
    }
  }
View Full Code Here

    bus.setPoller(poller);
  }

  @Test
  public void resolveQueueChannel() {
    MessageChannel registered = resolver.resolveDestination("queue:foo");
    DirectChannel testChannel = new DirectChannel();
    final CountDownLatch latch = new CountDownLatch(1);
    final List<Message<?>> received = new ArrayList<Message<?>>();
    testChannel.subscribe(new MessageHandler() {

      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        received.add(message);
        latch.countDown();
      }
    });
    bus.bindConsumer("queue:foo", testChannel, null);
    assertEquals(0, received.size());
    registered.send(MessageBuilder.withPayload("hello").build());
    try {
      assertTrue("latch timed out", latch.await(1, TimeUnit.SECONDS));
    }
    catch (InterruptedException e) {
      Thread.currentThread().interrupt();
View Full Code Here

    context.close();
  }

  @Test
  public void resolveTopicChannel() {
    MessageChannel registered = resolver.resolveDestination("topic:bar");
    PublishSubscribeChannel[] testChannels = {
      new PublishSubscribeChannel(), new PublishSubscribeChannel(), new PublishSubscribeChannel()
    };
    final CountDownLatch latch = new CountDownLatch(testChannels.length);
    final List<Message<?>> received = new ArrayList<Message<?>>();
    for (PublishSubscribeChannel testChannel : testChannels) {
      testChannel.subscribe(new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
          received.add(message);
          latch.countDown();
        }
      });
      bus.bindPubSubConsumer("topic:bar", testChannel, null);
    }
    assertEquals(0, received.size());
    registered.send(MessageBuilder.withPayload("hello").build());
    try {
      assertTrue("latch timed out", latch.await(1, TimeUnit.SECONDS));
    }
    catch (InterruptedException e) {
      Thread.currentThread().interrupt();
View Full Code Here

    context.close();
  }

  @Test
  public void resolveNonRegisteredChannel() {
    MessageChannel other = resolver.resolveDestination("other");
    assertSame(context.getBean("other"), other);
  }
View Full Code Here

  private void doRegisterConsumer(String bindingName, String channelName, MessageChannel moduleInputChannel,
      MessageProducerSupport adapter, RedisPropertiesAccessor properties) {
    DirectChannel bridgeToModuleChannel = new DirectChannel();
    bridgeToModuleChannel.setBeanFactory(this.getBeanFactory());
    bridgeToModuleChannel.setBeanName(channelName + ".bridge");
    MessageChannel bridgeInputChannel = addRetryIfNeeded(channelName, bridgeToModuleChannel, properties);
    adapter.setOutputChannel(bridgeInputChannel);
    adapter.setBeanName("inbound." + bindingName);
    adapter.afterPropertiesSet();
    Binding consumerBinding = Binding.forConsumer(bindingName, adapter, moduleInputChannel, properties);
    addBinding(consumerBinding);
View Full Code Here

        .setModuleDefinition(moduleDefinition)
        .build());
    when(module.getComponent(MessageBus.class)).thenReturn(bus);
    when(module.getName()).thenReturn(moduleDefinition.getName());
    DirectChannel output = new DirectChannel();
    MessageChannel proxy = (MessageChannel) new ProxyFactory(output).getProxy();
    when(module.getComponent("output", MessageChannel.class)).thenReturn(proxy);
    plugin.postProcessModule(module);
    List<?> interceptors = TestUtils.getPropertyValue(output, "interceptors.interceptors", List.class);
    assertEquals(0, interceptors.size());
View Full Code Here

    properties.put("suffix","bar");
    context.getEnvironment().getPropertySources().addLast(new PropertiesPropertySource("options", properties));
    context.register(TestConfiguration.class);
    context.refresh();

    MessageChannel input = context.getBean("input", MessageChannel.class);
    SubscribableChannel output = context.getBean("output", SubscribableChannel.class);

    final AtomicBoolean handled = new AtomicBoolean();
    output.subscribe(new MessageHandler() {
      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        handled.set(true);
        assertEquals("foohellobar", message.getPayload());
      }
    });
    input.send(new GenericMessage<String>("hello"));
    assertTrue(handled.get());
  }
View Full Code Here

    when(module.getProperties()).thenReturn(properties);
    when(module.getDescriptor()).thenReturn(
        new ModuleDescriptor.Builder().setGroup(moduleGroupName).setIndex(moduleIndex).setModuleDefinition(
            ModuleDefinitions.dummy("testjob", ModuleType.job)).build());

    MessageChannel stepsOut = new DirectChannel();
    when(module.getComponent("stepExecutionRequests.output", MessageChannel.class)).thenReturn(stepsOut);
    PollableChannel stepResultsIn = new QueueChannel();
    when(module.getComponent("stepExecutionReplies.input", MessageChannel.class)).thenReturn(stepResultsIn);
    PollableChannel stepsIn = new QueueChannel();
    when(module.getComponent("stepExecutionRequests.input", MessageChannel.class)).thenReturn(stepsIn);
    MessageChannel stepResultsOut = new DirectChannel();
    when(module.getComponent("stepExecutionReplies.output", MessageChannel.class)).thenReturn(stepResultsOut);
    jobPartitionerPlugin.preProcessModule(module);
    jobPartitionerPlugin.postProcessModule(module);
    checkBusBound(messageBus);
    stepsOut.send(new GenericMessage<String>("foo"));
    Message<?> stepExecutionRequest = stepsIn.receive(10000);
    assertThat(stepExecutionRequest, hasPayload("foo"));
    stepResultsOut.send(MessageBuilder.withPayload("bar")
        .copyHeaders(stepExecutionRequest.getHeaders()) // replyTo
        .build());
    assertThat(stepResultsIn.receive(10000), hasPayload("bar"));
    jobPartitionerPlugin.removeModule(module);
    checkBusUnbound(messageBus);
View Full Code Here

    }

    @Test
    public void testTwitterChannel(){
        log.debug("testTwitterChannel");
        MessageChannel twitterOutChannel = this.twitterTransformedChannel;
        Message<String> twitterUpdate = new GenericMessage<String>("22 Testing  http://www.google.es new Twitter samples for #springintegration "+RandomStringUtils.random(2));
        log.debug("twitterOutChannel message "+twitterUpdate.getPayload());
        twitterOutChannel.send(twitterUpdate);
        log.debug("twitterOutChannel");
    }
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.