Package com.rabbitmq.client

Examples of com.rabbitmq.client.Channel


    return recoveryChannel;
  }

  protected MockChannel mockChannel() throws IOException {
    MockChannel mockChannel = new MockChannel();
    Channel channel = mock(Channel.class);
    int channelNumber = new Random().nextInt(1000) + 1000;
    when(channel.getChannelNumber()).thenReturn(channelNumber);
    when(channel.toString()).thenReturn("channel-" + channelNumber);
    when(connection.createChannel()).thenReturn(channel);
    mockChannel.proxy = connectionProxy.createChannel();
    mockChannel.channelHandler = (ChannelHandler) Proxy.getInvocationHandler(mockChannel.proxy);
    mockChannel.delegate = mockChannel.channelHandler.delegate;
    return mockChannel;
View Full Code Here


    MockChannel mockChannel = channels.get(channelNumber);

    try {
      if (mockChannel == null) {
        mockChannel = new MockChannel();
        Channel channel = mock(Channel.class);
        when(connection.createChannel(eq(channelNumber))).thenReturn(channel);
        when(channel.getChannelNumber()).thenReturn(channelNumber);
        when(channel.toString()).thenReturn("channel-" + channelNumber);
        mockChannel.proxy = connectionProxy.createChannel(channelNumber);
        mockChannel.channelHandler = (ChannelHandler) Proxy.getInvocationHandler(mockChannel.proxy);
        mockChannel.delegate = mockChannel.channelHandler.delegate;
        channels.put(channelNumber, mockChannel);
      }
View Full Code Here

  }

  @Override
  @SuppressWarnings("unchecked")
  void createResources() throws IOException {
    Channel adminChannel = mockRecoveryChannel();
    MockChannel channel = mockChannel(1);

    Queue.DeclareOk declareOk = mock(Queue.DeclareOk.class);
    when(declareOk.getQueue()).thenReturn("test-queue");
    when(
        adminChannel.queueDeclare(eq("test-queue"), anyBoolean(), anyBoolean(), anyBoolean(),
            anyMap())).thenReturn(declareOk);
    when(
        channel.delegate.queueDeclare(eq("test-queue"), anyBoolean(), anyBoolean(), anyBoolean(),
            anyMap())).thenReturn(declareOk);
View Full Code Here

      delegate = callWithRetries(new Callable<Channel>() {
        @Override
        public Channel call() throws Exception {
          log.info("Recovering {}", ChannelHandler.this);
          previousMaxDeliveryTag = maxDeliveryTag;
          Channel channel = connectionHandler.createChannel(delegate.getChannelNumber());
          migrateConfiguration(channel);
          log.info("Recovered {}", ChannelHandler.this);
          return channel;
        }
      }, config.getChannelRecoveryPolicy(), recoveryStats, config.getRecoverableExceptions(), true, false);
View Full Code Here

      return callWithRetries(
          new Callable<Object>() {
            @Override
            public Object call() throws Exception {
              if ("createChannel".equals(method.getName())) {
                Channel channel = (Channel) Reflection.invoke(delegate, method, args);
                ChannelHandler channelHandler =
                    new ChannelHandler(ConnectionHandler.this, channel, new Config(config));
                Channel channelProxy =
                    (Channel) Proxy.newProxyInstance(Connection.class.getClassLoader(),
                        CHANNEL_TYPES, channelHandler);
                channelHandler.proxy = channelProxy;
                channels.put(Integer.valueOf(channel.getChannelNumber()).toString(), channelHandler);
                log.info("Created {}", channelHandler);
View Full Code Here

@Test
public class ChannelHandlerTest extends AbstractFunctionalTest {
  @Test(expectedExceptions = AlreadyClosedException.class)
  public void shouldThrowOnAlreadyClosedChannelInvocation() throws Throwable {
    mockConnection();
    Channel channel = mockChannel().proxy;
    when(channel.getCloseReason()).thenReturn(channelShutdownSignal());
    channel.close();
    channel.abort();
  }
View Full Code Here

    /**
     * Open channel
     */
    private Channel openChannel() throws IOException {
        log.trace("Creating channel...");
        Channel channel = conn.createChannel();
        log.debug("Created channel: {}", channel);
        // setup the basicQos
        if (endpoint.isPrefetchEnabled()) {
            channel.basicQos(endpoint.getPrefetchSize(), endpoint.getPrefetchCount(),
                    endpoint.isPrefetchGlobal());
        }
        return channel;
    }
View Full Code Here

    /**
     * Add a consumer thread for given channel
     */
    private void startConsumers() throws IOException {
        // First channel used to declare Exchange and Queue
        Channel channel = openChannel();
        if (getEndpoint().isDeclare()) {
            endpoint.declareExchangeAndQueue(channel);
        }
        startConsumer(channel);
        // Other channels
View Full Code Here

    try
    {
      ConnectionFactory factory = new ConnectionFactory();
      factory.setHost(_mqServer);
      connection = factory.newConnection();
      Channel channel = connection.createChannel();

      channel.exchangeDeclare(EXCHANGE_NAME, "topic");
      String queueName = channel.queueDeclare().getQueue();

      String bindingKey = _partition;
      channel.queueBind(queueName, EXCHANGE_NAME, bindingKey);

      System.out.println(" [*] " + _consumerId + " Waiting for messages on " + bindingKey + ". To exit press CTRL+C");

      QueueingConsumer consumer = new QueueingConsumer(channel);
      channel.basicConsume(queueName, true, consumer);

      while (true)
      {
        QueueingConsumer.Delivery delivery = consumer.nextDelivery();
        String message = new String(delivery.getBody());
View Full Code Here

   

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(mqServer);
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(EXCHANGE_NAME, "topic");

    for (int i = 0; i < count; i++)
    {
      int rand = ((int) (Math.random() * 10000) % SetupConsumerCluster.DEFAULT_PARTITION_NUMBER);
      String routingKey = "topic_" + rand;
      String message = "message_" + rand;

      channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes());
      System.out.println(" [x] Sent '" + routingKey + "':'" + message + "'");
     
      Thread.sleep(1000);
    }
   
View Full Code Here

TOP

Related Classes of com.rabbitmq.client.Channel

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.