subject, new AMQP.BasicProperties.Builder() .correlationId(instanceId.toString()) .headers(headers) .build(),
byte[] response = null; String corrId = UUID.randomUUID().toString(); BasicProperties props = new BasicProperties.Builder().correlationId(corrId).replyTo(replyQueue).build(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DeflaterOutputStream defos = new DeflaterOutputStream(baos);
builder.correlationId(headers.get(CORRELATION_ID_KEY));
.correlationId(correlationId) .headers(stringObjectMap) .build();
.correlationId(correlationId) .headers(stringObjectMap) .build();
.correlationId(request.getCorrelationId()) .deliveryMode(MessageProperties.PERSISTENT_TEXT_PLAIN.getDeliveryMode()) .build();
builder.contentType(message.getContentType()); builder.replyTo(message.getReplyTo()); builder.correlationId(message.getCorrelationId()); builder.contentEncoding(message.getContentEncoding()); Map<String, Object> headers = message.getHeaders();
private void processDelivery(Delivery delivery) throws Exception { BasicProperties props = delivery.getProperties(); BasicProperties replyProps = new BasicProperties.Builder().correlationId(props.getCorrelationId()).build(); DataInputStream data = new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(delivery.getBody()))); RenderMode mode = RenderMode.values()[data.readUnsignedByte()];
@Override public Event request(Event request, int duration, TimeUnit timeUnit) throws InterruptedException { requireNonNull(request, "event must be defined."); connect(); EventBuilder eventBuilder = new EventBuilder(request); String correlationId = UUID.randomUUID().toString(); eventBuilder .setRequestReplyType(Event.RequestReplyType.REQUEST) .setReplyTo(localQueueName) .setCorrelationId(correlationId); ReplyEvent replyEvent = new ReplyEvent(correlationId); addEventRequest(replyEvent); String message = Event.convertToJson(eventBuilder.build()); AMQP.BasicProperties props = new AMQP.BasicProperties .Builder() .replyTo(localQueueName) .correlationId(correlationId) .deliveryMode(MessageProperties.PERSISTENT_TEXT_PLAIN.getDeliveryMode()) .build(); try { producer.publish(rabbitMqConfig.businessExchangeName(), message, null, props); } catch (Exception e) { LOGGER.error("Unable to publish request with correlationId {}.", correlationId, e); } return replyEvent.getReply(duration, timeUnit); }
@Override public BasicProperties fromMessageProperties(final MessageProperties source, final String charset) { BasicProperties.Builder target = new BasicProperties.Builder(); target.headers(this.convertHeadersIfNecessary(source.getHeaders())) .timestamp(source.getTimestamp()) .messageId(source.getMessageId()) .userId(source.getUserId()) .appId(source.getAppId()) .clusterId(source.getClusterId()) .type(source.getType()); MessageDeliveryMode deliveryMode = source.getDeliveryMode(); if (deliveryMode != null) { target.deliveryMode(MessageDeliveryMode.toInt(deliveryMode)); } target.expiration(source.getExpiration()) .priority(source.getPriority()) .contentType(source.getContentType()) .contentEncoding(source.getContentEncoding()); String correlationId = source.getCorrelationId(); if (StringUtils.hasText(correlationId)) { target.correlationId(correlationId); } String replyTo = source.getReplyTo(); if (replyTo != null) { target.replyTo(replyTo); } return target.build(); }
propertiesBuilder.correlationId(B16.encode(optionalCorrelationId.get()));
@Override public BasicProperties fromMessageProperties(final MessageProperties source, final String charset) { BasicProperties.Builder target = new BasicProperties.Builder(); target.headers(this.convertHeadersIfNecessary(source.getHeaders())) .timestamp(source.getTimestamp()) .messageId(source.getMessageId()) .userId(source.getUserId()) .appId(source.getAppId()) .clusterId(source.getClusterId()) .type(source.getType()); MessageDeliveryMode deliveryMode = source.getDeliveryMode(); if (deliveryMode != null) { target.deliveryMode(MessageDeliveryMode.toInt(deliveryMode)); } target.expiration(source.getExpiration()) .priority(source.getPriority()) .contentType(source.getContentType()) .contentEncoding(source.getContentEncoding()); String correlationId = source.getCorrelationId(); if (StringUtils.hasText(correlationId)) { target.correlationId(correlationId); } String replyTo = source.getReplyTo(); if (replyTo != null) { target.replyTo(replyTo); } return target.build(); }
builder.contentType("text/plain"); builder.correlationId(toStr(message.properties().get(CorrelationId.name())));
/** * Method is called by ExecutorService and publishes message on RabbitMQ * * @return loggingEvent */ @Override public LoggingEvent call() throws Exception { if(zafiraConnected) { String payload = layout.format(loggingEvent); AMQP.BasicProperties.Builder b = new AMQP.BasicProperties().builder(); b.appId(identifier) .type(loggingEvent.getLevel().toString()) .correlationId(String.valueOf(correlationId)) .contentType("text/json"); createChannel().basicPublish(exchange, routingKey, b.build(), payload.getBytes()); } return loggingEvent; } }
/** * Method is called by ExecutorService and publishes message on RabbitMQ * * @return loggingEvent */ @Override public LoggingEvent call() throws Exception { if(zafiraConnected) { String payload = layout.format(loggingEvent); AMQP.BasicProperties.Builder b = new AMQP.BasicProperties().builder(); b.appId(identifier) .type(loggingEvent.getLevel().toString()) .correlationId(String.valueOf(correlationId)) .contentType("text/json"); createChannel().basicPublish(exchange, routingKey, b.build(), payload.getBytes()); } return loggingEvent; } }
public void response(JsonEnvelope envelope, Object object) { LOGGER.debug("Response to " + envelope.getReceiverInstance() + ", corrId is " + envelope.getCorrelationId()); String className = object.getClass().getName(); String jsonString = gson.toJson(object); try { // Create a message headers Map<String, Object> headers = new HashMap<>(); headers.put("sender", instanceId.toString()); headers.put("class", className); // Publish message to topic channel.basicPublish( "iris", envelope.getReceiverInstance(), new AMQP.BasicProperties.Builder() .correlationId(envelope.getCorrelationId()) .headers(headers) .build(), jsonString.getBytes() ); } catch (IOException e) { LOGGER.error("Error sending reply JSON message: " + object + " to queue: " + envelope.getReceiverInstance(), e); } }
/** * Build and populate the AMQP.BasicProperties using the RabbitMQMessage * * @param message the RabbitMQMessage to be used to get the properties * @return AMQP.BasicProperties object */ private AMQP.BasicProperties.Builder buildBasicProperties(RabbitMQMessage message) { AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties().builder(); builder.messageId(message.getMessageId()); builder.contentType(message.getContentType()); builder.replyTo(message.getReplyTo()); builder.correlationId(message.getCorrelationId()); builder.contentEncoding(message.getContentEncoding()); Map<String, Object> headers = message.getHeaders(); if (message.getSoapAction() != null) { headers.put(RabbitMQConstants.SOAP_ACTION, message.getSoapAction()); } builder.headers(headers); return builder; }
public static AMQP.BasicProperties box(Message msg) { AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder(); return builder.messageId(String.valueOf(msg.getMessageId())) .appId(msg.getAppId()) .clusterId(msg.getClusterId()) .contentEncoding(msg.getContentEncoding()) .contentType(msg.getContentType()) .correlationId(msg.getCorrelationId()) .deliveryMode((int) msg.getDeliveryMode()) .expiration(msg.getExpiration()) .headers(msg.getHeaders()) .priority((int) msg.getPriority()) .replyTo(msg.getReplyTo()) .timestamp(new Date(msg.getTimestamp())) .type(msg.getType()) .userId(msg.getUserId()) .build(); }
public static AMQP.BasicProperties fromJson( JsonObject json ) { if ( json == null ) { return new AMQP.BasicProperties(); } return new AMQP.BasicProperties.Builder() .contentType(json.getString("contentType")) .contentEncoding(json.getString("contentEncoding")) .headers(asMap(json.getJsonObject("headers"))) .deliveryMode(json.getInteger("deliveryMode")) .priority(json.getInteger("priority")) .correlationId(json.getString("correlationId")) .replyTo(json.getString("replyTo")) .expiration(json.getString("expiration")) .messageId(json.getString("messageId")) .timestamp(parseDate(json.getString("timestamp"))) .type(json.getString("type")) .userId(json.getString("userId")) .appId(json.getString("appId")) .clusterId(json.getString("clusterId")).build(); }
public BasicProperties toBasicProperties() { BasicProperties.Builder builder = new BasicProperties.Builder(); return builder.appId(appId).clusterId(clusterId).contentEncoding(contentEncoding).contentType(contentType).correlationId(correlationId) .deliveryMode(deliveryMode).expiration(expiration).headers(headers).messageId(messageId).priority(priority).replyTo(replyTo) .timestamp(timestamp).type(type).userId(userId).build(); }