Package com.rabbitmq.client

Examples of com.rabbitmq.client.Channel


        // use a separate connection and channel to avoid race conditions with any operations that are blocked
        // waiting for the reconnection to finish...and don't cache anything otherwise you get the same problem!
        try {
            Connection connection = connectionFactory.newConnection(new Address[] { new Address(host) });
            Channel channel = connection.createChannel();

            channel.queueDeclare("testQueue", false, false, false, new HashMap<String, Object>());
            channel.queueBind("testQueue", "amq.topic", "#");

            channel.close();
            connection.close();

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
View Full Code Here


        };
        ConnectionFactory cf = newConnectionFactory(eh);
        assertEquals(cf.getExceptionHandler(), eh);
        Connection conn = cf.newConnection();
        assertEquals(conn.getExceptionHandler(), eh);
        Channel ch = conn.createChannel();
        String q = ch.queueDeclare().getQueue();
        ch.basicConsume(q, new DefaultConsumer(ch) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                throw new RuntimeException("oops");
            }
        });
        ch.basicPublish("", q, null, "".getBytes());
        wait(latch);
    }
View Full Code Here

        succeedBind(queue, arguments);
    }

    private void failBind(String queue, HashMap<String, Object> arguments) {
        try {
            Channel ch = connection.createChannel();
            ch.queueBind(queue, "amq.headers", "", arguments);
            fail("Expected failure");
        } catch (IOException e) {
          checkShutdownSignal(AMQP.PRECONDITION_FAILED, e);
        }
    }
View Full Code Here

          checkShutdownSignal(AMQP.PRECONDITION_FAILED, e);
        }
    }

    private void succeedBind(String queue, HashMap<String, Object> arguments) throws IOException {
        Channel ch = connection.createChannel();
        ch.queueBind(queue, "amq.headers", "", arguments);
        ch.close();
    }
View Full Code Here

        assertFailValidation(args(null));
        assertFailValidation(args(Arrays.asList(1, 2, 3)));
    }

    private void assertFailValidation(Map<String, Object> args) throws IOException {
        Channel ch = connection.createChannel();
        String queue = ch.queueDeclare().getQueue();
        try {
            ch.basicConsume(queue, true, args, new QueueingConsumer(ch));
            fail("Validation should fail for " + args);
        } catch (IOException ioe) {
            checkShutdownSignal(AMQP.PRECONDITION_FAILED, ioe);
        }
    }
View Full Code Here

    return exchange;
  }

  public void setExchange(String exchange) {
    this.exchange = exchange;
    Channel mq;
    try {
      mq = getChannel();
      synchronized (mq) {
        mq.exchangeDeclare(exchange, "topic", true, false, null);
      }
    } catch (IOException e) {
      errorHandler.error(e.getMessage(), e, ErrorCode.GENERIC_FAILURE);
    }
  }
View Full Code Here

            //  Connect to the AMQP broker
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost(hostName);
            factory.setPort(portNumber);
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();

            for (;;) {

                //  Send a message.
                channel.basicPublish("PIPELINE", null, null,
                    "Hello, World???".getBytes());

                //  Sleep for one second.
                Thread.sleep (1000);
            }
View Full Code Here

            //  Connect to the AMQP broker
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost(hostName);
            factory.setPort(portNumber);
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();

            //  Establish the REQ/REP wiring.
            String queueName = channel.queueDeclare().getQueue();
            QueueingConsumer consumer = new QueueingConsumer(channel);
            channel.basicConsume(queueName, true, consumer);

            //  Send the request
            AMQP.BasicProperties properties = new AMQP.BasicProperties();
            properties.setReplyTo(queueName);
            channel.basicPublish("", "REQREP", properties,
                "Hello!".getBytes());

            //  Get and print the reply
            QueueingConsumer.Delivery delivery = consumer.nextDelivery();
            String reply = new String(delivery.getBody());
View Full Code Here

            //  Connect to the AMQP broker
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost(hostName);
            factory.setPort(portNumber);
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();

            //  Establish the PUB/SUB wiring
            String queueName = channel.queueDeclare().getQueue();
            channel.queueBind(queueName, "PIPELINE", null);
            QueueingConsumer consumer = new QueueingConsumer(channel);
            channel.basicConsume(queueName, true, consumer);

            for (;;) {

                //  Get next request
                String msg = consumer.nextDelivery().getBody().toString();
View Full Code Here

            //  Connect to the AMQP broker
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost(hostName);
            factory.setPort(portNumber);
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();

            //  Establish the REQ/REP wiring.
            channel.queueDeclare("REQREP", true, false, false, null);
            QueueingConsumer consumer = new QueueingConsumer(channel);
            channel.basicConsume("REQREP", true, consumer);

            for (;;) {

                //  Get next request
                QueueingConsumer.Delivery delivery = consumer.nextDelivery();
                String replyTo = delivery.getProperties().getReplyTo();
                String correlationId = delivery.getProperties().getCorrelationId();

                BasicProperties props =
                  (BasicProperties) (delivery.getProperties().clone());
                // We must set the correlation ID, because it is used
                // by AMQP and 0MQ clients for correlating replies
                props.setReplyTo(null);
                System.err.println("processing request");

                //  Send the reply
                channel.basicPublish("", replyTo, props, "World!".getBytes());
            }
        } catch (Exception e) {
            System.err.println("Main thread caught exception: " + e);
            e.printStackTrace();
            System.exit(1);
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.