Package org.springframework.messaging

Examples of org.springframework.messaging.MessageHandler


    // anyway....
    //1) lets send an outbound message so that our gateway has something to listen for


    MessageHandler inboundMessageHandler = new AbstractReplyProducingMessageHandler() {
      @Override
      protected Object handleRequestMessage(Message<?> requestMessage) {
         logger.debug("Processing incoming message for inbound-gw and produce a reply");
        Assert.assertEquals(requestMessage.getPayload(), smsRequest);
        count.incrementAndGet();
        return MessageBuilder.withPayload(
            smsResponse).copyHeadersIfAbsent( requestMessage.getHeaders()).build();

      }
    };
    this.in1.subscribe(inboundMessageHandler);

    // this is handler for reply from inbound-gateway
    MessageHandler replyHandler = new MessageHandler() {
      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        logger.debug("Reply handler receives: "+message.getPayload());
        Assert.assertEquals(message.getPayload(), smsResponse);
      }
View Full Code Here


  }

  private void doRegisterProducer(final String name, MessageChannel moduleOutputChannel,
      AmqpOutboundEndpoint delegate, String replyTo, RabbitPropertiesAccessor properties) {
    Assert.isInstanceOf(SubscribableChannel.class, moduleOutputChannel);
    MessageHandler handler = new SendingHandler(delegate, replyTo, properties);
    EventDrivenConsumer consumer = new EventDrivenConsumer((SubscribableChannel) moduleOutputChannel, handler);
    consumer.setBeanFactory(getBeanFactory());
    consumer.setBeanName("outbound." + name);
    consumer.afterPropertiesSet();
    Binding producerBinding = Binding.forProducer(name, moduleOutputChannel, consumer, properties);
View Full Code Here

      final Producer<Integer, byte[]> producer = new Producer<Integer, byte[]>(producerConfig);
      final ProducerConfiguration<Integer, byte[]> producerConfiguration = new ProducerConfiguration<Integer, byte[]>(
          producerMetadata, producer);

      MessageHandler messageHandler = new AbstractMessageHandler() {

        @Override
        protected void handleMessageInternal(Message<?> message) throws Exception {
          producerConfiguration.send(message);
        }
      };

      Assert.isInstanceOf(SubscribableChannel.class, moduleOutputChannel);
      MessageHandler handler = new SendingHandler(messageHandler, topicName, accessor);
      EventDrivenConsumer consumer = new EventDrivenConsumer((SubscribableChannel) moduleOutputChannel, handler);
      consumer.setBeanFactory(this.getBeanFactory());
      consumer.setBeanName("outbound." + name);
      consumer.afterPropertiesSet();
      Binding producerBinding = Binding.forProducer(name, moduleOutputChannel, consumer, accessor);
View Full Code Here

      Properties properties) {
    validateConsumerProperties(name, properties, Collections.emptySet());
    final MessageChannel requestChannel = this.findOrCreateRequestReplyChannel("requestor." + name);
    // TODO: handle Pollable ?
    Assert.isInstanceOf(SubscribableChannel.class, requests);
    ((SubscribableChannel) requests).subscribe(new MessageHandler() {

      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        requestChannel.send(message);
      }
    });

    ExecutorChannel replyChannel = this.findOrCreateRequestReplyChannel("replier." + name);
    replyChannel.subscribe(new MessageHandler() {

      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        replies.send(message);
      }
View Full Code Here

  @Override
  public void bindReplier(String name, final MessageChannel requests, MessageChannel replies,
      Properties properties) {
    validateConsumerProperties(name, properties, Collections.emptySet());
    SubscribableChannel requestChannel = this.findOrCreateRequestReplyChannel("requestor." + name);
    requestChannel.subscribe(new MessageHandler() {

      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        requests.send(message);
      }
    });

    // TODO: handle Pollable ?
    Assert.isInstanceOf(SubscribableChannel.class, replies);
    final SubscribableChannel replyChannel = this.findOrCreateRequestReplyChannel("replier." + name);
    ((SubscribableChannel) replies).subscribe(new MessageHandler() {

      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        replyChannel.send(message);
      }
View Full Code Here

    MessageChannel input = module.getComponent("input", MessageChannel.class);
    assertNotNull(input);
    SubscribableChannel output = module.getComponent("output", SubscribableChannel.class);
    assertNotNull(output);
    final AtomicReference<Message<?>> result = new AtomicReference<Message<?>>();
    output.subscribe(new MessageHandler() {

      @Override
      public void handleMessage(Message<?> message) {
        result.set(message);
      }
View Full Code Here

    DirectChannel moduleInputChannel = new DirectChannel();
    messageBus.bindProducer("bad.0", moduleOutputChannel, null);
    messageBus.bindConsumer("bad.0", moduleInputChannel, null);
    Message<?> message = MessageBuilder.withPayload("bad").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar").build();
    final CountDownLatch latch = new CountDownLatch(3);
    moduleInputChannel.subscribe(new MessageHandler() {

      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        latch.countDown();
        throw new RuntimeException("bad");
View Full Code Here

    properties.put("autoBindDLQ", "true");
    properties.put("maxAttempts", "1"); // disable retry
    properties.put("requeue", "false");
    DirectChannel moduleInputChannel = new DirectChannel();
    moduleInputChannel.setBeanName("dlqTest");
    moduleInputChannel.subscribe(new MessageHandler() {

      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        throw new RuntimeException("foo");
      }
View Full Code Here

    MessageChannel producer = getSourceOutputChannel(streamName);
    SubscribableChannel consumer = getSinkInputChannel(tapName);
    SubscribableChannel streamConsumer = getSinkInputChannel(streamName);

    // Add a dummy consumer to the stream in case there is none
    streamConsumer.subscribe(new MessageHandler() {

      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
      }
    });
View Full Code Here

  @Before
  public void setup() {
    env = new Environment();
    latch = new CountDownLatch(MSG_COUNT * 4);
    output.subscribe(new MessageHandler() {

      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        latch.countDown();
      }
View Full Code Here

TOP

Related Classes of org.springframework.messaging.MessageHandler

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.