INT-4041: AMQP: Map receivedUserId

JIRA: https://jira.spring.io/browse/INT-4041

Polish the `AMQP-1.6.0` link to be more generic and refer
This commit is contained in:
Gary Russell
2016-05-26 10:01:15 -04:00
committed by Artem Bilan
parent d57db56a39
commit 16f9c9ae49
4 changed files with 23 additions and 4 deletions

View File

@@ -215,9 +215,9 @@ public class DefaultAmqpHeaderMapper extends AbstractHeaderMapper<MessagePropert
if (StringUtils.hasText(type)) {
headers.put(AmqpHeaders.TYPE, type);
}
String userId = amqpMessageProperties.getUserId();
String userId = amqpMessageProperties.getReceivedUserId();
if (StringUtils.hasText(userId)) {
headers.put(AmqpHeaders.USER_ID, userId);
headers.put(AmqpHeaders.RECEIVED_USER_ID, userId);
}
for (String jsonHeader : JsonHeaders.HEADERS) {

View File

@@ -73,6 +73,11 @@ public class StubRabbitConnectionFactory implements ConnectionFactory {
return null;
}
@Override
public String getUsername() {
return null;
}
@Override
public void addConnectionListener(ConnectionListener listener) {
}

View File

@@ -174,7 +174,7 @@ public class DefaultAmqpHeaderMapperTests {
Date testTimestamp = new Date();
amqpProperties.setTimestamp(testTimestamp);
amqpProperties.setType("test.type");
amqpProperties.setUserId("test.userId");
amqpProperties.setReceivedUserId("test.userId");
amqpProperties.setHeader(AmqpHeaders.SPRING_REPLY_CORRELATION, "test.correlation");
amqpProperties.setHeader(AmqpHeaders.SPRING_REPLY_TO_STACK, "test.replyTo2");
Map<String, Object> headerMap = headerMapper.toHeadersFromReply(amqpProperties);
@@ -195,7 +195,7 @@ public class DefaultAmqpHeaderMapperTests {
assertEquals("test.replyTo", headerMap.get(AmqpHeaders.REPLY_TO));
assertEquals(testTimestamp, headerMap.get(AmqpHeaders.TIMESTAMP));
assertEquals("test.type", headerMap.get(AmqpHeaders.TYPE));
assertEquals("test.userId", headerMap.get(AmqpHeaders.USER_ID));
assertEquals("test.userId", headerMap.get(AmqpHeaders.RECEIVED_USER_ID));
assertEquals("test.correlation", headerMap.get(AmqpHeaders.SPRING_REPLY_CORRELATION));
assertEquals("test.replyTo2", headerMap.get(AmqpHeaders.SPRING_REPLY_TO_STACK));
}

View File

@@ -1137,6 +1137,20 @@ JSON converter to be selected.
This applies to both the outbound channel adapter and gateway.
[[amqp-user-id]]
=== Outbound User Id
Spring AMQP _version 1.6_ introduced a mechanism to allow the specification of a default user id for outbound messages.
It has always been possible to set the `AmqpHeaders.USER_ID` header which will now take precedence over the default.
This might be useful to message recipients; for inbound messages, if the message publisher sets the property, it is made available in the `AmqpHeaders.RECEIVED_USER_ID` header.
Note that RabbitMQ https://www.rabbitmq.com/validated-user-id.html[validates that the user id is the actual user id for the connection or one for which impersonation is allowed].
To configure a default user id for outbound messages, configure it on a `RabbitTemplate` and configure the outbound adapter or gateway to use that template.
Similarly, to set the user id property on replies, inject an appropriately configured template into the inbound gateway.
See the http://docs.spring.io/spring-amqp/reference/html/_reference.html#template-user-id[Spring AMQP documentation] for more information.
[[amqp-channels]]
=== AMQP Backed Message Channels