List of usage examples for com.rabbitmq.client BasicProperties getHeaders
public abstract Map<String, Object> getHeaders();
From source file:org.apache.flume.RabbitMQUtil.java
License:Apache License
public static Map<String, String> getHeaders(BasicProperties properties) { Preconditions.checkArgument(properties != null, "properties cannot be null."); Map<String, String> headers = new CaseInsensitiveMap(); setTimestamp(headers, properties);/* ww w. jav a 2s . com*/ Map<String, Object> rabbitmqHeaders = properties.getHeaders(); if (null != rabbitmqHeaders) { for (Map.Entry<String, Object> kvp : rabbitmqHeaders.entrySet()) { if (!headers.containsKey(kvp.getKey()) && null != kvp.getValue()) { if (log.isInfoEnabled()) log.info("header=" + kvp.getKey() + " value=" + kvp.getValue()); headers.put(kvp.getKey(), kvp.getValue().toString()); } } } return headers; }
From source file:org.eclipse.ditto.services.connectivity.messaging.rabbitmq.RabbitMQConsumerActor.java
License:Open Source License
private static Map<String, String> extractHeadersFromMessage(final BasicProperties properties, final Envelope envelope) { final Map<String, String> headersFromProperties = getHeadersFromProperties(properties.getHeaders()); // set headers specific to rmq messages if (properties.getReplyTo() != null) { headersFromProperties.put(ExternalMessage.REPLY_TO_HEADER, properties.getReplyTo()); }/*from w w w. j a va 2 s .c o m*/ if (properties.getCorrelationId() != null) { headersFromProperties.put(DittoHeaderDefinition.CORRELATION_ID.getKey(), properties.getCorrelationId()); } if (properties.getContentType() != null) { headersFromProperties.put(ExternalMessage.CONTENT_TYPE_HEADER, properties.getContentType()); } headersFromProperties.put(MESSAGE_ID_HEADER, Long.toString(envelope.getDeliveryTag())); return headersFromProperties; }
From source file:org.mule.transport.amqp.AmqpMuleMessageFactory.java
License:Open Source License
private void addBasicProperties(final DefaultMuleMessage muleMessage, final Map<String, Object> messageProperties, final BasicProperties amqpProperties) { if (amqpProperties == null) return;/*from w w w .j a v a 2s . c o m*/ putIfNonNull(messageProperties, AmqpConstants.APP_ID, amqpProperties.getAppId()); putIfNonNull(messageProperties, AmqpConstants.CONTENT_ENCODING, amqpProperties.getContentEncoding()); putIfNonNull(messageProperties, AmqpConstants.CONTENT_TYPE, amqpProperties.getContentType()); final String correlationId = amqpProperties.getCorrelationId(); putIfNonNull(messageProperties, AmqpConstants.CORRELATION_ID, correlationId); putIfNonNull(messageProperties, MuleProperties.MULE_CORRELATION_ID_PROPERTY, correlationId); muleMessage.setCorrelationId(correlationId); putIfNonNull(messageProperties, AmqpConstants.DELIVERY_MODE, amqpProperties.getDeliveryMode()); putIfNonNull(messageProperties, AmqpConstants.EXPIRATION, amqpProperties.getExpiration()); final String messageId = amqpProperties.getMessageId(); putIfNonNull(messageProperties, AmqpConstants.MESSAGE_ID, messageId); putIfNonNull(messageProperties, MuleProperties.MULE_MESSAGE_ID_PROPERTY, messageId); muleMessage.setUniqueId(messageId); putIfNonNull(messageProperties, AmqpConstants.PRIORITY, amqpProperties.getPriority()); final String replyTo = amqpProperties.getReplyTo(); putIfNonNull(messageProperties, AmqpConstants.REPLY_TO, replyTo); muleMessage.setReplyTo(replyTo); putIfNonNull(messageProperties, AmqpConstants.TIMESTAMP, amqpProperties.getTimestamp()); putIfNonNull(messageProperties, AmqpConstants.TYPE, amqpProperties.getType()); putIfNonNull(messageProperties, AmqpConstants.USER_ID, amqpProperties.getUserId()); messageProperties.putAll(amqpProperties.getHeaders()); }
From source file:org.mule.transport.amqp.AmqpMuleMessageFactoryTestCase.java
License:Open Source License
public static void checkInboundProperties(final AmqpMessage amqpMessage, final MuleMessage muleMessage) { assertEquals(amqpMessage.getConsumerTag(), muleMessage.getProperty(AmqpConstants.CONSUMER_TAG, PropertyScope.INBOUND)); final Envelope envelope = amqpMessage.getEnvelope(); assertEquals(envelope.getDeliveryTag(), muleMessage.getProperty(AmqpConstants.DELIVERY_TAG, PropertyScope.INBOUND)); assertEquals(envelope.isRedeliver(), muleMessage.getProperty(AmqpConstants.REDELIVER, PropertyScope.INBOUND)); assertEquals(envelope.getExchange(), muleMessage.getProperty(AmqpConstants.EXCHANGE, PropertyScope.INBOUND)); assertEquals(envelope.getRoutingKey(), muleMessage.getProperty(AmqpConstants.ROUTING_KEY, PropertyScope.INBOUND)); final BasicProperties amqpProperties = amqpMessage.getProperties(); assertEquals(amqpProperties.getAppId(), muleMessage.getProperty(AmqpConstants.APP_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getContentEncoding(), muleMessage.getProperty(AmqpConstants.CONTENT_ENCODING, PropertyScope.INBOUND)); assertEquals(amqpProperties.getContentType(), muleMessage.getProperty(AmqpConstants.CONTENT_TYPE, PropertyScope.INBOUND)); assertEquals(amqpProperties.getCorrelationId(), muleMessage.getProperty(AmqpConstants.CORRELATION_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getCorrelationId(), muleMessage.getCorrelationId()); assertEquals(amqpProperties.getDeliveryMode(), muleMessage.getProperty(AmqpConstants.DELIVERY_MODE, PropertyScope.INBOUND)); assertEquals(amqpProperties.getExpiration(), muleMessage.getProperty(AmqpConstants.EXPIRATION, PropertyScope.INBOUND)); assertEquals(amqpProperties.getMessageId(), muleMessage.getProperty(AmqpConstants.MESSAGE_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getMessageId(), muleMessage.getUniqueId()); assertEquals(amqpProperties.getPriority(), muleMessage.getProperty(AmqpConstants.PRIORITY, PropertyScope.INBOUND)); assertEquals(amqpProperties.getReplyTo(), muleMessage.getProperty(AmqpConstants.REPLY_TO, PropertyScope.INBOUND)); assertEquals(amqpProperties.getReplyTo(), muleMessage.getReplyTo()); assertEquals(amqpProperties.getTimestamp(), muleMessage.getProperty(AmqpConstants.TIMESTAMP, PropertyScope.INBOUND)); assertEquals(amqpProperties.getType(), muleMessage.getProperty(AmqpConstants.TYPE, PropertyScope.INBOUND)); assertEquals(amqpProperties.getUserId(), muleMessage.getProperty(AmqpConstants.USER_ID, PropertyScope.INBOUND)); for (final Entry<String, Object> header : amqpProperties.getHeaders().entrySet()) { assertEquals(header.getValue(), muleMessage.getProperty(header.getKey(), PropertyScope.INBOUND)); }/*ww w. ja va 2 s. c o m*/ }
From source file:org.mule.transport.amqp.harness.AmqpTestClient.java
License:Open Source License
public void validateAmqpDeliveredMessage(String expectedPayload, String expectedCustomHeaderValue, byte[] body, BasicProperties basicProperties) { assertThat(new String(body), is(equalTo(expectedPayload))); assertThat(basicProperties.getHeaders().get("customHeader").toString(), is(equalTo(expectedCustomHeaderValue))); }
From source file:org.mule.transport.amqp.internal.domain.AmqpMuleMessageFactoryTestCase.java
License:Open Source License
public static void checkInboundProperties(final AmqpMessage amqpMessage, final MuleMessage muleMessage) { assertEquals(amqpMessage.getConsumerTag(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CONSUMER_TAG, PropertyScope.INBOUND)); final Envelope envelope = amqpMessage.getEnvelope(); assertEquals(envelope.getDeliveryTag(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_DELIVERY_TAG, PropertyScope.INBOUND)); assertEquals(envelope.isRedeliver(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_REDELIVER, PropertyScope.INBOUND)); assertEquals(envelope.getExchange(), muleMessage.getProperty(AmqpConnector.EXCHANGE, PropertyScope.INBOUND)); assertEquals(envelope.getRoutingKey(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_ROUTING_KEY, PropertyScope.INBOUND)); final BasicProperties amqpProperties = amqpMessage.getProperties(); assertEquals(amqpProperties.getAppId(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_APP_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getContentEncoding(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CONTENT_ENCODING, PropertyScope.INBOUND)); assertEquals(amqpProperties.getContentType(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CONTENT_TYPE, PropertyScope.INBOUND)); assertEquals(amqpProperties.getClusterId(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CLUSTER_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getCorrelationId(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CORRELATION_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getCorrelationId(), muleMessage.getCorrelationId()); assertEquals(amqpProperties.getDeliveryMode(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_DELIVERY_MODE, PropertyScope.INBOUND)); assertEquals(amqpProperties.getExpiration(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_EXPIRATION, PropertyScope.INBOUND)); assertEquals(amqpProperties.getMessageId(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_MESSAGE_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getMessageId(), muleMessage.getUniqueId()); assertEquals(amqpProperties.getPriority(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_PRIORITY, PropertyScope.INBOUND)); assertEquals(amqpProperties.getReplyTo(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_REPLY_TO, PropertyScope.INBOUND)); assertEquals(amqpProperties.getReplyTo(), muleMessage.getReplyTo()); assertEquals(amqpProperties.getTimestamp(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_TIMESTAMP, PropertyScope.INBOUND)); assertEquals(amqpProperties.getType(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_TYPE, PropertyScope.INBOUND)); assertEquals(amqpProperties.getUserId(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_USER_ID, PropertyScope.INBOUND)); for (final Entry<String, Object> header : amqpProperties.getHeaders().entrySet()) { assertEquals(header.getValue(), muleMessage.getProperty(header.getKey(), PropertyScope.INBOUND)); }//www . j a va 2s . c om }
From source file:org.smartdeveloperhub.curator.connector.BrokerControllerTest.java
License:Apache License
@Test public void testPublishMessage$unexpectedFailure() throws Exception { final BrokerController sut = newInstance(); final DeliveryChannel dc = ProtocolFactory.newDeliveryChannel().withExchangeName("exchangeName") .withRoutingKey("routingKey").build(); final String message = "message"; new MockUp<ConnectionFactory>() { @Mock//from w w w . j a v a2s .c o m public void setHost(final String host) { } @Mock public void setPort(final int port) { } @Mock public void setVirtualHost(final String virtualHost) { } @Mock public void setThreadFactory(final ThreadFactory threadFactory) { } @Mock public Connection newConnection() throws IOException, TimeoutException { return BrokerControllerTest.this.connection; } }; new Expectations() { { BrokerControllerTest.this.connection.createChannel(); this.result = BrokerControllerTest.this.channel; BrokerControllerTest.this.channel.basicPublish(dc.exchangeName(), dc.routingKey(), true, (BasicProperties) this.any, message.getBytes()); this.result = new ShutdownSignalException(true, true, null, BrokerControllerTest.this.channel); } }; sut.connect(); try { sut.publishMessage(dc, message); } catch (final IOException e) { assertThat(e.getMessage(), equalTo( "Unexpected failure while publishing message [message] to exchange 'exchangeName' and routing key 'routingKey' using broker localhost:5672/: clean connection shutdown")); assertThat(e.getCause(), instanceOf(ShutdownSignalException.class)); } new Verifications() { { BasicProperties s; BrokerControllerTest.this.channel.basicPublish(dc.exchangeName(), dc.routingKey(), true, s = withCapture(), message.getBytes()); assertThat(s.getDeliveryMode(), equalTo(2)); assertThat(s.getHeaders().get(BrokerController.BROKER_CONTROLLER_MESSAGE), instanceOf(Long.class)); } }; }
From source file:org.smartdeveloperhub.curator.connector.BrokerControllerTest.java
License:Apache License
@Test public void testPublishMessage$shareChannelInThread() throws Exception { final BrokerController sut = newInstance(); final DeliveryChannel dc = ProtocolFactory.newDeliveryChannel().withExchangeName("exchangeName") .withRoutingKey("routingKey").build(); final String message = "message"; new MockUp<ConnectionFactory>() { @Mock// w w w. j a va 2 s .c om public void setHost(final String host) { } @Mock public void setPort(final int port) { } @Mock public void setVirtualHost(final String virtualHost) { } @Mock public void setThreadFactory(final ThreadFactory threadFactory) { } @Mock public Connection newConnection() throws IOException, TimeoutException { return BrokerControllerTest.this.connection; } }; new Expectations() { { BrokerControllerTest.this.connection.createChannel(); this.result = BrokerControllerTest.this.channel; this.minTimes = 2; this.maxTimes = 2; BrokerControllerTest.this.channel.basicPublish(dc.exchangeName(), dc.routingKey(), true, (BasicProperties) this.any, message.getBytes()); this.minTimes = 2; this.maxTimes = 2; } }; sut.connect(); sut.publishMessage(dc, message); sut.publishMessage(dc, message); new Verifications() { { BasicProperties s; BrokerControllerTest.this.channel.basicPublish(dc.exchangeName(), dc.routingKey(), true, s = withCapture(), message.getBytes()); assertThat(s.getDeliveryMode(), equalTo(2)); assertThat(s.getHeaders().get(BrokerController.BROKER_CONTROLLER_MESSAGE), instanceOf(Long.class)); } }; }
From source file:org.smartdeveloperhub.harvesters.it.notification.CollectorControllerTest.java
License:Apache License
@Test public void testPublishEvent$usesCurrentChannelAndImplementsNotificationProtocol(@Mocked final Channel channel) throws Exception { new MockUp<ConnectionManager>() { private boolean connected = false; @Mock(invocations = 1)//from w w w . j a va 2s .co m void connect() { this.connected = true; } @Mock(invocations = 1) void disconnect() { } @Mock boolean isConnected() { return this.connected; } @Mock Channel channel() { return channel; } @Mock(invocations = 1) Channel currentChannel() { return channel; } @Mock(invocations = 0) void discardChannel() { } }; final CollectorConfiguration defaultCollector = defaultCollector(); new Expectations() { { channel.basicPublish(defaultCollector.getExchangeName(), Notifications.routingKey(ProjectCreatedEvent.class), true, (BasicProperties) this.any, (byte[]) this.any); } }; final CollectorController sut = CollectorController.createPublisher(defaultCollector); final ProjectCreatedEvent event = new ProjectCreatedEvent(); event.setInstance(defaultCollector.getInstance()); event.setNewProjects(Arrays.asList("1", "2")); sut.connect(); try { sut.publishEvent(event); } finally { sut.disconnect(); } new Verifications() { { BasicProperties props; byte[] body; channel.basicPublish(defaultCollector.getExchangeName(), Notifications.routingKey(ProjectCreatedEvent.class), true, props = withCapture(), body = withCapture()); assertThat(new String(body), equalTo(EventUtil.marshall(event))); assertThat(props.getHeaders().get(CONTENT_TYPE), equalTo((Object) Notifications.MIME)); assertThat(props.getDeliveryMode(), equalTo(MessageProperties.MINIMAL_PERSISTENT_BASIC.builder().build().getDeliveryMode())); } }; }
From source file:org.smartdeveloperhub.harvesters.it.notification.NotificationConsumer.java
License:Apache License
private void verifyHeader(final BasicProperties properties) throws IOException { final Object header = properties.getHeaders().get(HttpHeaders.CONTENT_TYPE); checkNotNull(header, "No %s header defined", HttpHeaders.CONTENT_TYPE); checkArgument(Notifications.MIME.equals(header.toString()), "Unsupported %s header (%s)", HttpHeaders.CONTENT_TYPE, header); }