Package org.springframework.amqp.rabbit.core

Examples of org.springframework.amqp.rabbit.core.RabbitTemplate


    final CountDownLatch latch = new CountDownLatch(1);
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cachingConnectionFactory);
    container.setMessageListener(new MessageListener() {
      @Override
      public void onMessage(Message message) {
        RabbitTemplate rabbitTemplate = new RabbitTemplate(cachingConnectionFactory);
        rabbitTemplate.setChannelTransacted(true);
        // should use same channel as container
        rabbitTemplate.convertAndSend("foo", "bar", "baz");
        latch.countDown();
      }
    });
    container.setQueueNames("queue");
    container.setChannelTransacted(true);
View Full Code Here


    final CountDownLatch latch = new CountDownLatch(1);
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cachingConnectionFactory);
    container.setMessageListener(new MessageListener() {
      @Override
      public void onMessage(Message message) {
        RabbitTemplate rabbitTemplate = new RabbitTemplate(cachingTemplateConnectionFactory);
        rabbitTemplate.setChannelTransacted(true);
        // should use same channel as container
        rabbitTemplate.convertAndSend("foo", "bar", "baz");
        latch.countDown();
      }
    });
    container.setQueueNames("queue");
    container.setChannelTransacted(true);
View Full Code Here

    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(singleConnectionFactory);
    container.setMessageListener(new ChannelAwareMessageListener() {
      @Override
      public void onMessage(Message message, Channel channel) {
        exposed.set(channel);
        RabbitTemplate rabbitTemplate = new RabbitTemplate(singleConnectionFactory);
        rabbitTemplate.setChannelTransacted(true);
        // should use same channel as container
        rabbitTemplate.convertAndSend("foo", "bar", "baz");
        latch.countDown();
      }

    });
    container.setQueueNames("queue");
View Full Code Here

    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(singleConnectionFactory);
    container.setMessageListener(new ChannelAwareMessageListener() {
      @Override
      public void onMessage(Message message, Channel channel) {
        exposed.set(channel);
        RabbitTemplate rabbitTemplate = new RabbitTemplate(singleConnectionFactory);
        rabbitTemplate.setChannelTransacted(true);
        // should use same channel as container
        rabbitTemplate.convertAndSend("foo", "bar", "baz");
        latch.countDown();
      }

    });
    container.setQueueNames("queue");
View Full Code Here

    final CountDownLatch latch = new CountDownLatch(1);
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cachingConnectionFactory);
    container.setMessageListener(new MessageListener() {
      @Override
      public void onMessage(Message message) {
        RabbitTemplate rabbitTemplate = new RabbitTemplate(cachingConnectionFactory);
        rabbitTemplate.setChannelTransacted(true);
        // should use same channel as container
        rabbitTemplate.convertAndSend("foo", "bar", "baz");
        latch.countDown();
      }
    });
    container.setQueueNames("queue");
    container.setChannelTransacted(true);
View Full Code Here

  private Queue queue3;

  @Test
  public void testBindingsDeclared() throws Exception {

    RabbitTemplate template = new RabbitTemplate(connectionFactory);
    template.convertAndSend(fanoutTest.getName(), "", "message");
    template.convertAndSend(fanoutTest.getName(), queue.getName(), "message");
    Thread.sleep(200);
    // The queue is anonymous so it will be deleted at the end of the test, but it should get the message as long as
    // we use the same connection
    String result = (String) template.receiveAndConvert(queue.getName());
    assertEquals("message", result);
    result = (String) template.receiveAndConvert(queue.getName());
    assertEquals("message", result);
  }
View Full Code Here

  }

  @Test
  public void testDirectExchangeBindings() throws Exception {

    RabbitTemplate template = new RabbitTemplate(connectionFactory);

    template.convertAndSend(directTest.getName(), queue.getName(), "message");
    Thread.sleep(200);

    String result = (String) template.receiveAndConvert(queue.getName());
    assertEquals("message", result);

    template.convertAndSend(directTest.getName(), "", "message2");
    Thread.sleep(200);

    assertNull(template.receiveAndConvert(queue.getName()));

    result = (String) template.receiveAndConvert(queue2.getName());
    assertEquals("message2", result);

    template.convertAndSend(directTest.getName(), queue2.getName(), "message2");
    Thread.sleep(200);

    assertNull(template.receiveAndConvert(queue2.getName()));

    template.convertAndSend(directTest.getName(), queue3.getName(), "message2");
    Thread.sleep(200);

    result = (String) template.receiveAndConvert(queue3.getName());
    assertEquals("message2", result);
  }
View Full Code Here

  }

  @Test
  public void testSendAndReceiveFromVolatileQueue() throws Exception {

    RabbitTemplate template = new RabbitTemplate(connectionFactory);

    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    Queue queue = admin.declareQueue();
    template.convertAndSend(queue.getName(), "message");
    String result = (String) template.receiveAndConvert(queue.getName());
    assertEquals("message", result);

  }
View Full Code Here

  @Test
  public void testReceiveFromNonExistentVirtualHost() throws Exception {

    connectionFactory.setVirtualHost("non-existent");
    RabbitTemplate template = new RabbitTemplate(connectionFactory);
    // Wrong vhost is very unfriendly to client - the exception has no clue (just an EOF)
    exception.expect(AmqpIOException.class);
    String result = (String) template.receiveAndConvert("foo");
    assertEquals("message", result);

  }
View Full Code Here

  }

  @Test
  public void testSendAndReceiveFromVolatileQueueAfterImplicitRemoval() throws Exception {

    RabbitTemplate template = new RabbitTemplate(connectionFactory);

    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    Queue queue = admin.declareQueue();
    template.convertAndSend(queue.getName(), "message");

    // Force a physical close of the channel
    connectionFactory.destroy();

    // The queue was removed when the channel was closed
    exception.expect(AmqpIOException.class);

    String result = (String) template.receiveAndConvert(queue.getName());
    assertEquals("message", result);

  }
View Full Code Here

TOP

Related Classes of org.springframework.amqp.rabbit.core.RabbitTemplate

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.