@Override public CompletableFuture<Void> sendAsync(Optional<String> key, byte[] payload) { BasicProperties.Builder builder = defaultProperties.builder().timestamp(new Date()); if (messagePersistence) { builder.deliveryMode(2); } BasicProperties props = builder.build(); CompletableFuture<Void> future = new CompletableFuture<>(); long msgId = channel.getNextPublishSeqNo(); ackSet.add(msgId); futureConcurrentHashMap.putIfAbsent(msgId, future); try { channel.basicPublish(exchange, key.orElse(""), props, payload); } catch (Exception e) { future.completeExceptionally(e); } return future; }
@Override public void emit(final Event event) { requireNonNull(event, "Cannot emit a null event!"); final BasicProperties props = new BasicProperties().builder() .contentType("application/ld+json").contentEncoding("UTF-8").build(); service.serialize(event).ifPresent(message -> { try { channel.basicPublish(exchangeName, routingKey, mandatory, immediate, props, message.getBytes()); } catch (final IOException ex) { LOGGER.error("Error writing to broker: {}", ex.getMessage()); } }); }
private void publishMessage(final String exchangeName, final String routingKey, final String message) throws IOException { final Channel aChannel = currentChannel(); try { LOGGER.debug("Publishing message to exchange '{}' and routing key '{}'. Payload: \n{}",exchangeName,routingKey,message); final Map<String, Object> headers=Maps.newLinkedHashMap(); headers.put(BROKER_CONTROLLER_MESSAGE,this.messageCounter.incrementAndGet()); aChannel. basicPublish( exchangeName, routingKey, true, MessageProperties.MINIMAL_PERSISTENT_BASIC.builder().headers(headers).build(), message.getBytes()); } catch (final IOException e) { discardChannel(aChannel); LOGGER.warn("Could not publish message [{}] to exchange '{}' and routing key '{}': {}",message,exchangeName,routingKey,e.getMessage()); throw e; } catch (final Exception e) { discardChannel(aChannel); final String errorMessage = String.format("Unexpected failure while publishing message [%s] to exchange '%s' and routing key '%s' using broker %s:%s%s: %s",message,exchangeName,routingKey,this.broker.host(),this.broker.port(),this.broker.virtualHost(),e.getMessage()); LOGGER.error(errorMessage); throw new IOException(errorMessage,e); } }
os.close(); AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties().builder(); builder.messageId(synCtx.getMessageID()); builder.deliveryMode(MessageProperties.MINIMAL_PERSISTENT_BASIC.getDeliveryMode());
MessageProperties. MINIMAL_PERSISTENT_BASIC. builder(). headers(headers). build(),
MessageProperties. MINIMAL_PERSISTENT_BASIC. builder(). headers(headers). build(),
RabbitMqQueue rabbitMqQueue = (RabbitMqQueue) queue; AMQP.BasicProperties.Builder builder = MessageProperties.MINIMAL_PERSISTENT_BASIC.builder(); String messageRoutingKey = rabbitMqQueue.getMessageRoutingKey(); if (!isQueueInitialized(queue)) {
BasicProperties props = new BasicProperties().builder().replyTo(Address.AMQ_RABBITMQ_REPLY_TO).build(); channel1.getChannel().basicPublish("", TEST_RELEASE_CONSUMER_Q, props, "foo".getBytes()); Channel replyChannel = connectionFactory.createConnection().createChannel(false);
AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties().builder(); if (message.getTimestamp() != null) {
/** * 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; } }
/** * <p> * Flags the message to be a persistent message. A persistent message survives a total broker failure as it is * persisted to disc if not already delivered to and acknowledged by all consumers. * </p> * * <p> * Important: This flag only has affect if the queues on the broker are flagged as durable. * </p> * * @return The modified message */ public Message persistent() { basicProperties = basicProperties.builder() .deliveryMode(DELIVERY_MODE_PERSISTENT) .build(); return this; }
/** * 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; }
/** * Publishes a message via the given channel while using the specified delivery options. * * @param channel The channel used to publish the message on * @param deliveryOptions The delivery options to use * @throws IOException */ public void publish(Channel channel, DeliveryOptions deliveryOptions) throws IOException { // Assure to have a timestamp if (basicProperties.getTimestamp() == null) { basicProperties.builder().timestamp(new Date()); } boolean mandatory = deliveryOptions == DeliveryOptions.MANDATORY; boolean immediate = deliveryOptions == DeliveryOptions.IMMEDIATE; LOGGER.info("Publishing message to exchange '{}' with routing key '{}' (deliveryOptions: {}, persistent: {})", new Object[] { exchange, routingKey, deliveryOptions, basicProperties.getDeliveryMode() == 2 }); channel.basicPublish(exchange, routingKey, mandatory, immediate, basicProperties, bodyContent); LOGGER.info("Successfully published message to exchange '{}' with routing key '{}'", exchange, routingKey); }
public MessageWrapper() { this.properties = new AMQP.BasicProperties().builder(); }
public MessageWrapper(String body, AMQP.BasicProperties properties) { this.body = body; this.properties = properties.builder(); }
@Override public void emit(final Event event) { requireNonNull(event, "Cannot emit a null event!"); final BasicProperties props = new BasicProperties().builder() .contentType("application/ld+json").contentEncoding("UTF-8").build(); service.serialize(event).ifPresent(message -> { try { channel.basicPublish(exchangeName, routingKey, mandatory, immediate, props, message.getBytes()); } catch (final IOException ex) { LOGGER.error("Error writing to broker: {}", ex.getMessage()); } }); }
private AMQP.BasicProperties createHeader(String msgType) { AMQP.BasicProperties.Builder header = new AMQP.BasicProperties().builder(); Map<String, Object> props = new HashMap<String, Object>(); props.put("type", msgType); header.headers(props); return header.build(); }
/** * Sets the content type of this message. * * @param contentType The content type * @return The modified message */ public Message contentType(String contentType) { basicProperties = basicProperties.builder() .contentType(contentType) .build(); return this; }
/** * Sets the content charset encoding of this message. * * @param charset The charset encoding * @return The modified message */ public Message contentEncoding(String charset) { basicProperties = basicProperties.builder() .contentEncoding(charset) .build(); return this; }