@Override public void open(Configuration config) throws Exception { super.open(config); ConnectionFactory factory = setupConnectionFactory(); try { connection = factory.newConnection(); channel = connection.createChannel(); if (channel == null) { throw new RuntimeException("None of RabbitMQ channels are available"); } setupQueue(); consumer = new QueueingConsumer(channel); RuntimeContext runtimeContext = getRuntimeContext(); if (runtimeContext instanceof StreamingRuntimeContext && ((StreamingRuntimeContext) runtimeContext).isCheckpointingEnabled()) { autoAck = false; // enables transaction mode channel.txSelect(); } else { autoAck = true; } LOG.debug("Starting RabbitMQ source with autoAck status: " + autoAck); channel.basicConsume(queueName, autoAck, consumer); } catch (IOException e) { throw new RuntimeException("Cannot create RMQ connection with " + queueName + " at " + rmqConnectionConfig.getHost(), e); } running = true; }
Connection connection = RabbitConnection.getConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(getQueueName(), false, false, false, null); consumer = new QueueingConsumer(channel); channel.basicConsume(getQueueName(), false,consumer);
Connection connection = RabbitConnection.getConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(getQueueName(), false, false, false, null); consumer = new QueueingConsumer(channel); channel.basicConsume(getQueueName(), true,consumer); channel.basicQos(2);
public RabbitConsumer( Channel channel ) { consumer = new QueueingConsumer( channel ); }
@Override protected void connectCallback(final Channel channel) throws IOException { final QueueingConsumer consumer = new QueueingConsumer(channel); consumerHolder.set(consumer); }
public static QueueingConsumer consume(Channel channel, String queueName, boolean autoAck, String consumerTag) throws IOException { QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, autoAck, consumerTag, consumer); return consumer; }
public void execute() throws Exception { Channel channel = AMQPCommon.connect(); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume("trade.eq.q", true, consumer); while (true) { QueueingConsumer.Delivery msg = consumer.nextDelivery(); String message = new String(msg.getBody()); System.out.println("message received: " + message); String[] parts = message.split(","); long shares = new Long(parts[2]).longValue(); Thread.sleep(1000); } }
public MQReceiver(String host, int port, String queue_name, int qos) throws IOException, TimeoutException { super(host, port, queue_name); channel.basicQos(qos); consumer = new QueueingConsumer(channel); channel.basicConsume(queue_name, false, consumer); }
public static void main(String[] args) throws Exception { Channel channel = AMQPCommon.connect(); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume("music.q", true, consumer); while (true) { QueueingConsumer.Delivery msg = consumer.nextDelivery(); System.out.println("PROCESSING MUSIC ORDER: " + new String(msg.getBody())); Thread.sleep(2000); } } }
public static void main(String[] args) throws Exception { Channel channel = AMQPCommon.connect(); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume("movie.q", true, consumer); while (true) { QueueingConsumer.Delivery msg = consumer.nextDelivery(); System.out.println("PROCESSING MOVIE ORDER: " + new String(msg.getBody())); Thread.sleep(2000); } } }
public static void main(String[] args) throws Exception { Channel channel = AMQPCommon.connect(); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume("book.q", true, consumer); while (true) { QueueingConsumer.Delivery msg = consumer.nextDelivery(); System.out.println("PROCESSING BOOK ORDER: " + new String(msg.getBody())); Thread.sleep(2000); } } }
public static void main(String[] args) throws Exception { Channel channel = AMQPCommon.connect(); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume("order.q", true, consumer); while (true) { QueueingConsumer.Delivery msg = consumer.nextDelivery(); String orderType = msg.getProperties().getHeaders().get("type").toString(); String orderItem = new String(msg.getBody()); processor.get(orderType).processOrder(orderItem); Thread.sleep(2000); } } }
@Override public Outcome onInitialization() { try { // Prepare the connection, channel and consumer this.connection = this.createConnection(); this.channel = this.connection.createChannel(); this.consumer = new QueueingConsumer(this.channel); return Outcome.SUCCESS; } catch (final KeyManagementException | NoSuchAlgorithmException | TimeoutException | URISyntaxException | IOException e) { this.handleInitializationError(e); return Outcome.FAILURE; } }
@Override public Outcome onInitialization() { try { // Prepare the connection, channel and consumer this.connection = this.createConnection(); this.channel = this.connection.createChannel(); this.consumer = new QueueingConsumer(this.channel); return Outcome.SUCCESS; } catch (final KeyManagementException | NoSuchAlgorithmException | TimeoutException | URISyntaxException | IOException e) { this.handleInitializationError(e); return Outcome.FAILURE; } }
public void dispatchMessages() throws Exception { Channel channel = AMQPCommon.connect(); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicQos(1); channel.basicConsume("trade.eq.q", false, consumer); while (true) { QueueingConsumer.Delivery msg = consumer.nextDelivery(); channel.basicAck(msg.getEnvelope().getDeliveryTag(), false); new Thread(new POJOThreadProcessor( this, new String(msg.getBody()))).start(); numThreads++; System.out.println("Threads: " + numThreads); } }
public static void main(String[] args) throws Exception { Channel channel = AMQPCommon.connect(); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicQos(1); channel.basicConsume("trade.eq.q", false, consumer); while (true) { QueueingConsumer.Delivery msg = consumer.nextDelivery(); System.out.println("message received: " + new String(msg.getBody())); Thread.sleep(2000); channel.basicAck(msg.getEnvelope().getDeliveryTag(), false); } } }
public static void main(String[] args) throws Exception { Channel channel = AMQPCommon.connect(); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicQos(1); channel.basicConsume("trade.eq.q", false, consumer); while (true) { QueueingConsumer.Delivery msg = consumer.nextDelivery(); Thread.sleep(2000); System.out.println("Trade placed: " + new String(msg.getBody())); channel.basicAck(msg.getEnvelope().getDeliveryTag(), false); } } }
@Bean QueueingConsumer queueingConsumer() throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(messageQueueHostname); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(Constants.ANSWERSHEET_DATA_QUEUE, true, false, false, null); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(Constants.ANSWERSHEET_DATA_QUEUE, true, consumer); return consumer; }
public DualChannelPool(RabbitMQConnectionFactory connectionFactory, int connectionPoolSize) { dualChannelPool = new LinkedBlockingDeque<>(); try { Connection connection = connectionFactory.createConnection(); for (int i = 0; i < connectionPoolSize; i++) { Channel channel = connection.createChannel(); QueueingConsumer consumer = new QueueingConsumer(channel); String replyQueueName = channel.queueDeclare().getQueue(); dualChannelPool.add(new DualChannel(connection, channel, consumer, replyQueueName)); } } catch (IOException e) { throw new AxisRabbitMQException("Error creating dual channel pool", e); } }
public GetDeadLetterMessages(String queueName) throws Exception { this.queueName = queueName; factory = new ConnectionFactory(); factory.setHost(rabbitmq_host); connection = factory.newConnection(); channel = connection.createChannel(); //Add Dead letter queue channel.exchangeDeclare(queueName, "fanout", true); channel.queueDeclare(queueName, true, false, false, null); channel.queueBind(queueName, queueName, ""); consumer = new QueueingConsumer(channel); }