@Override public void run() { Message msg = wire.toMessage(bytes, basicProperties); if (CloudBus.HEADER_DEAD_LETTER.equals(envelope.getRoutingKey())) { handleDeadLetter(msg); } else { handleNoRouteLetter(msg); } }
ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); //**The threads part is as follows** channel.exchangeDeclare(EXCHANGE_NAME, "direct"); String queueName = channel.queueDeclare().getQueue(); // This part will biend the queue with the severity (login for eg:) for(String severity : argv){ channel.queueBind(queueName, EXCHANGE_NAME, routingKey); } boolean autoAck = false; channel.basicConsume(queueName, autoAck, "myConsumerTag", new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String routingKey = envelope.getRoutingKey(); String contentType = properties.contentType; long deliveryTag = envelope.getDeliveryTag(); // (process the message components here ...) channel.basicAck(deliveryTag, false); } });
@Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); System.out.println("ReceiveLogsTopic1 [x] Received '" + envelope.getRoutingKey() + "':'" + message + "'"); } };
private void populateRoutingInfoHeaders(final Message message, final Envelope envelope) { if (envelope != null) { message.setHeader(RabbitMQConstants.ROUTING_KEY, envelope.getRoutingKey()); message.setHeader(RabbitMQConstants.EXCHANGE_NAME, envelope.getExchange()); message.setHeader(RabbitMQConstants.DELIVERY_TAG, envelope.getDeliveryTag()); message.setHeader(RabbitMQConstants.REDELIVERY_TAG, envelope.isRedeliver()); } }
private static Map<String, Object> headers(final BasicProperties props, Envelope envelope) { Map<String, Object> result = props.getHeaders().entrySet().stream().collect(toMap(Entry::getKey, MessageFactory::headerValue)); result.put("DeliveryTag", envelope.getDeliveryTag()); result.put("Exchange", envelope.getExchange()); result.put("RoutingKey", envelope.getRoutingKey()); result.put("Redeliver", envelope.isRedeliver()); return result; }
@Override public void handleDelivery( String consumerTag, Envelope envelope, BasicProperties properties, byte[] body ) throws IOException { try { Message message = SerializationUtils.deserializeObject( body ); this.logger.finer( this.sourceName + " received a message " + message.getClass().getSimpleName() + " on routing key '" + envelope.getRoutingKey() + "'."); this.messageQueue.add( message ); } catch( ClassNotFoundException | IOException e ) { this.logger.severe( this.sourceName + ": a message could not be deserialized. => " + e.getClass().getSimpleName()); Utils.logException( this.logger, e ); this.messageQueue.errorWhileReceivingMessage(); } }
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) { logger.debug("job update for: " + envelope.getRoutingKey()); String message = new String(body); message = message.replaceAll("(?m)^", " "); // Here we parse the message and get the job status and push it // to the Event bus, this will be picked by // AiravataJobStatusUpdator and store in to registry logger.debug("************************************************************"); logger.debug("AMQP Message recieved \n" + message); logger.debug("************************************************************"); try { String jobID = envelope.getRoutingKey().split("\\.")[0]; MonitorID monitorID = new MonitorID(null, jobID, null, null, null, null,null); monitorID.setStatus(parser.parseMessage(message)); publisher.publish(monitorID); } catch (AiravataMonitorException e) { logger.error(e.getMessage(), e); } }
private Event parseMessage(Envelope envelope, AMQP.BasicProperties props, byte[] body) { // Create the event passing in the body Event event = EventBuilder.withBody(body); // Get the headers from properties, exchange, and routing-key Map<String, String> headers = buildHeaders(props); String exchange = envelope.getExchange(); if (exchange != null && !exchange.isEmpty()) { headers.put("exchange", exchange); } String routingKey = envelope.getRoutingKey(); if (routingKey != null && !routingKey.isEmpty()) { headers.put("routing-key", routingKey); } event.setHeaders(headers); return event; }
boolean autoAck = false; channel.basicConsume(queueName, autoAck, "myConsumerTag", new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String routingKey = envelope.getRoutingKey(); String contentType = properties.getContentType(); long deliveryTag = envelope.getDeliveryTag(); // (process the message components here ...) channel.basicAck(deliveryTag, false); } });
@Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { // Not for us. if (!envelope.getRoutingKey().equalsIgnoreCase(id)) return; String message = new String(body); try { Object newMsg = filter(message); // if newSgw == null, that means the message has been filtered. if (newMsg != null) { deliverPush(new Deliver(newMsg, new BroadcasterFuture<Object>(newMsg), message), true); } } catch (Throwable t) { logger.error("failed to push message: " + message, t); } } };
public void rePublish(GetResponse response) { Envelope envelope = response.getEnvelope(); try { channel.basicPublish(envelope.getExchange(), envelope.getRoutingKey(), response.getProps(), response.getBody()); } catch (IOException e) { e.printStackTrace(); } }
@Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { Object o = Jboot.me().getSerializer().deserialize(body); notifyListeners(envelope.getRoutingKey(), o); } });
/** * Handles a delivery and passes to message handler. * * @param delivery the newly arrived message including metadata */ @Override public void processDelivery(Delivery delivery) { try { TaskMessage taskMessage = codec.deserialise(delivery.getMessageData(), TaskMessage.class); synchronized (syncLock) { messageHandler.handleMessage(taskMessage,delivery.getEnvelope().getRoutingKey()); } } catch (CodecException e) { LOGGER.error("Error encountered trying to process delivery from queue.", e); } }
/** * {@inheritDoc} */ @Override public void handleDelivery(final String consumerTag, final Envelope envelope, final BasicProperties properties, final byte[] body) throws IOException { final String payload=new String(body, "UTF-8"); final String routingKey=envelope.getRoutingKey(); final AcknowledgeableNotification notification= new AcknowledgeableNotification( super.getChannel(), envelope.getDeliveryTag()); try { verifyHeader(properties); this.notifications. offer( findHandler(routingKey). suspend(notification,payload)); } catch(final Exception e) { LOGGER.error("Discarding message:\n{}\nReason:\n",payload,e); notification.acknowledge(); } }
/** * {@inheritDoc} */ @Override public void handleDelivery(final String consumerTag, final Envelope envelope, final BasicProperties properties, final byte[] body) throws IOException { final String payload=new String(body, "UTF-8"); final String routingKey=envelope.getRoutingKey(); final AcknowledgeableNotification notification= new AcknowledgeableNotification( super.getChannel(), envelope.getDeliveryTag()); try { verifyHeader(properties); this.notifications. offer( findHandler(routingKey). suspend(notification,payload)); } catch(final Exception e) { LOGGER.error("Discarding message:\n{}\nReason:\n",payload,e); notification.acknowledge(); } }
@Override public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException { if (closed) return; long deliveryTag = envelope.getDeliveryTag(); channelHandler.maxDeliveryTag = deliveryTag = deliveryTag + channelHandler.previousMaxDeliveryTag; delegate.handleDelivery( consumerTag, new Envelope(deliveryTag, envelope.isRedeliver(), envelope.getExchange(), envelope.getRoutingKey()), properties, body); }
@Override public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException { if (closed) return; long deliveryTag = envelope.getDeliveryTag(); channelHandler.maxDeliveryTag = deliveryTag = deliveryTag + channelHandler.previousMaxDeliveryTag; delegate.handleDelivery( consumerTag, new Envelope(deliveryTag, envelope.isRedeliver(), envelope.getExchange(), envelope.getRoutingKey()), properties, body); }
public static void populate(JsonObject json, Envelope envelope) { if (envelope == null) return; put("deliveryTag", envelope.getDeliveryTag(), json); put("isRedeliver", envelope.isRedeliver(), json); put("exchange", envelope.getExchange(), json); put("routingKey", envelope.getRoutingKey(), json); }
private void handleMessage(Exchange outputExchange, RabbitPublisher publisher, Message message) { try { //change in logback.xml to DEBUG level to see every message payload logged log.debugWithParams("Received message.", "payload", new String(message.payload), "metadata", message.basicProperties); publisher.call( outputExchange, new RoutingKey(message.envelope.getRoutingKey()), message.basicProperties, new Payload(message.payload) ) .doOnSuccess(ignore -> message.acknowledger.ack()) .doOnError(throwable -> message.acknowledger.reject()) .subscribe(); }catch (Exception e){ message.acknowledger.reject(); } }
private DeliveredMessage(QueueingConsumer.Delivery delivery) { super(delivery.getBody()); redelivery = delivery.getEnvelope().isRedeliver(); deliveryTag = delivery.getEnvelope().getDeliveryTag(); routingKey = delivery.getEnvelope().getRoutingKey(); exchange = delivery.getEnvelope().getExchange(); className = delivery.getProperties().getClassName(); clusterId = delivery.getProperties().getClusterId(); contentEncoding = delivery.getProperties().getContentEncoding(); contentType = delivery.getProperties().getContentType(); correlationId = delivery.getProperties().getCorrelationId(); deliveryMode = delivery.getProperties().getDeliveryMode(); expiration = delivery.getProperties().getExpiration(); headers = delivery.getProperties().getHeaders(); messageId = delivery.getProperties().getMessageId(); priority = delivery.getProperties().getPriority(); replyTo = delivery.getProperties().getReplyTo(); timestamp = delivery.getProperties().getTimestamp(); type = delivery.getProperties().getType(); userId = delivery.getProperties().getUserId(); }