本文整理汇总了Java中org.springframework.amqp.core.MessageProperties.setHeader方法的典型用法代码示例。如果您正苦于以下问题:Java MessageProperties.setHeader方法的具体用法?Java MessageProperties.setHeader怎么用?Java MessageProperties.setHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.amqp.core.MessageProperties
的用法示例。
在下文中一共展示了MessageProperties.setHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJoinTraceCompleteSuccess
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
public void testJoinTraceCompleteSuccess() {
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setHeader(TraceMessageHeaders.TRACE_ID_NAME, "123");
messageProperties.setHeader(TraceMessageHeaders.SPAN_ID_NAME, "456");
messageProperties.setHeader(TraceMessageHeaders.SPAN_NAME_NAME, "amqp");
messageProperties.setHeader(TraceMessageHeaders.PARENT_ID_NAME, "111");
messageProperties.setHeader(TraceMessageHeaders.PROCESS_ID_NAME, "process");
final Message message = new Message("Test".getBytes(), messageProperties);
final Span span = spanExtractor.joinTrace(message);
Assert.assertEquals("0000000000000123", span.traceIdString());
Assert.assertEquals("0000000000000456", Span.idToHex(span.getSpanId()));
Assert.assertEquals("amqp", span.getName());
Assert.assertEquals("0000000000000111", Span.idToHex(span.getParents().get(0)));
Assert.assertEquals("process", span.getProcessId());
}
示例2: testBeforeSendWithCurrentSpanOnServerReceiveFromMessage
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
public void testBeforeSendWithCurrentSpanOnServerReceiveFromMessage() {
when(tracer.isTracing()).thenReturn(false);
final Span parentSpan = mock(Span.class, "parentSpan");
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setHeader("messageSent", Boolean.TRUE.toString());
final Message message = new Message("Test".getBytes(), messageProperties);
when(extractor.joinTrace(eq(message))).thenReturn(parentSpan);
final Span newSpan = mock(Span.class, "newSpan");
when(tracer.createSpan(anyString(), eq(parentSpan))).thenReturn(newSpan);
final Span span = spanManager.beforeSend(message, "exchange");
verify(injector).inject(eq(newSpan), eq(message));
assertEquals(newSpan, span);
verify(newSpan).logEvent(eq(Span.SERVER_RECV));
}
示例3: testBeforeSendWithCurrentSpanOnServerReceiveFromTracer
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
public void testBeforeSendWithCurrentSpanOnServerReceiveFromTracer() {
final Span currentSpan = mock(Span.class, "currentSpan");
when(tracer.getCurrentSpan()).thenReturn(currentSpan);
when(tracer.isTracing()).thenReturn(true);
final Span newSpan = mock(Span.class, "newSpan");
when(tracer.createSpan(anyString(), eq(currentSpan))).thenReturn(newSpan);
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setHeader("messageSent", Boolean.TRUE.toString());
final Message message = new Message("Test".getBytes(), messageProperties);
final Span span = spanManager.beforeSend(message, "exchange");
verify(injector).inject(eq(newSpan), eq(message));
assertEquals(newSpan, span);
verify(newSpan).logEvent(eq(Span.SERVER_RECV));
}
示例4: shouldReceiveOnConfigPub
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
public void shouldReceiveOnConfigPub() throws Exception {
final String apiKey = "jV5bnJWK";
final String channel = "temp";
final String payload = "{ 'a' : '52T' }";
final Long epochMilli = 1490001001000L;
Instant timestamp = Instant.ofEpochMilli(epochMilli);
MessageProperties messageProperties = new MessageProperties();
messageProperties.setHeader("apiKey", apiKey);
messageProperties.setHeader("channel", channel);
messageProperties.setHeader("ts", epochMilli);
Message message = new Message(payload.getBytes("UTF-8"), messageProperties);
deviceEventRabbitEndpoint.onDataPub(message);
verify(deviceEventProcessor, times(1)).process(apiKey, channel, payload.getBytes("UTF-8"), timestamp);
}
示例5: shouldNotSendAnyEventThroughGatewayIfDeviceIsDisabled
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
public void shouldNotSendAnyEventThroughGatewayIfDeviceIsDisabled() throws Exception {
Tenant tenant = tenantRepository.findByDomainName("konker");
Application application = applicationRepository.findByTenantAndName(tenant.getId(), "smartffkonker");
Optional.of(deviceRegisterService.findByTenantDomainNameAndDeviceGuid(REGISTERED_TENANT_DOMAIN,REGISTERED_DEVICE_GUID))
.filter(device -> !device.isActive())
.orElseGet(() -> deviceRegisterService.switchEnabledDisabled(tenant, application, THE_DEVICE_GUID).getResult());
subject.send(event,destinationUri,data,device.getTenant(),device.getApplication());
MessageProperties properties = new MessageProperties();
properties.setHeader(RabbitMQDataConfig.MSG_HEADER_APIKEY, device.getApiKey());
properties.setHeader(RabbitMQDataConfig.MSG_HEADER_CHANNEL, data.get(DEVICE_MQTT_CHANNEL));
Message message = new Message(event.getPayload().getBytes("UTF-8"), properties);
verify(rabbitTemplate,never()).convertAndSend("data.sub", message);
verify(deviceLogEventService,never()).logIncomingEvent(Mockito.any() , Mockito.any());
verify(deviceLogEventService,never()).logOutgoingEvent(Mockito.any() , Mockito.any());
}
示例6: createThing
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
@Description("Tests the creation of a target/thing by calling the same method that incoming RabbitMQ messages would access.")
public void createThing() {
final String knownThingId = "1";
final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED);
messageProperties.setHeader(MessageHeaderKey.THING_ID, "1");
final Message message = messageConverter.toMessage(new byte[0], messageProperties);
final Target targetMock = mock(Target.class);
final ArgumentCaptor<String> targetIdCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<URI> uriCaptor = ArgumentCaptor.forClass(URI.class);
when(controllerManagementMock.findOrRegisterTargetIfItDoesNotexist(targetIdCaptor.capture(),
uriCaptor.capture())).thenReturn(targetMock);
when(controllerManagementMock.findOldestActiveActionByTarget(any())).thenReturn(Optional.empty());
amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT, "vHost");
// verify
assertThat(targetIdCaptor.getValue()).as("Thing id is wrong").isEqualTo(knownThingId);
assertThat(uriCaptor.getValue().toString()).as("Uri is not right").isEqualTo("amqp://vHost/MyTest");
}
示例7: updateAttributes
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
@Description("Tests the target attribute update by calling the same method that incoming RabbitMQ messages would access.")
public void updateAttributes() {
final String knownThingId = "1";
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
messageProperties.setHeader(MessageHeaderKey.THING_ID, "1");
messageProperties.setHeader(MessageHeaderKey.TOPIC, "UPDATE_ATTRIBUTES");
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
attributeUpdate.getAttributes().put("testKey1", "testValue1");
attributeUpdate.getAttributes().put("testKey2", "testValue2");
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(attributeUpdate,
messageProperties);
when(controllerManagementMock.updateControllerAttributes(targetIdCaptor.capture(), attributesCaptor.capture()))
.thenReturn(null);
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost");
// verify
assertThat(targetIdCaptor.getValue()).as("Thing id is wrong").isEqualTo(knownThingId);
assertThat(attributesCaptor.getValue()).as("Attributes is not right")
.isEqualTo(attributeUpdate.getAttributes());
}
示例8: updateActionStatusWithoutActionId
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
@Description("Tests the update of an action of a target without a exist action id")
public void updateActionStatusWithoutActionId() {
when(controllerManagementMock.findActionWithDetails(any())).thenReturn(Optional.empty());
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(1L, DmfActionStatus.DOWNLOAD);
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(actionUpdateStatus,
messageProperties);
try {
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost");
fail("AmqpRejectAndDontRequeueException was excepeted since no action id was set");
} catch (final AmqpRejectAndDontRequeueException exception) {
// test ok - exception was excepted
}
}
示例9: updateActionStatusWithoutExistActionId
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
@Description("Tests the update of an action of a target without a exist action id")
public void updateActionStatusWithoutExistActionId() {
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
when(controllerManagementMock.findActionWithDetails(any())).thenReturn(Optional.empty());
final DmfActionUpdateStatus actionUpdateStatus = createActionUpdateStatus(DmfActionStatus.DOWNLOAD);
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(actionUpdateStatus,
messageProperties);
try {
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost");
fail("AmqpRejectAndDontRequeueException was excepeted since no action id was set");
} catch (final AmqpRejectAndDontRequeueException exception) {
// test ok - exception was excepted
}
}
示例10: addSpanIdToRequest
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Override
public void addSpanIdToRequest(SpanId spanId) {
MessageProperties messageProperties = message.getMessageProperties();
if (spanId == null) {
messageProperties.setHeader(Headers.Sampled.getName(), "0");
} else {
messageProperties.setHeader(Headers.Sampled.getName(), "1");
messageProperties.setHeader(Headers.TraceId.getName(), IdConversion.convertToString(spanId.traceId));
messageProperties.setHeader(Headers.SpanId.getName(), IdConversion.convertToString(spanId.spanId));
if (spanId.nullableParentId() != null) {
messageProperties.setHeader(Headers.ParentSpanId.getName(), IdConversion.convertToString(spanId.parentId));
}
}
}
示例11: testInjectSpanAlreadySampledSuccess
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
public void testInjectSpanAlreadySampledSuccess() {
final AmqpMessagingSpanInjector spanInjector = new AmqpMessagingSpanInjector(new TraceKeys());
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setHeader(TraceMessageHeaders.SAMPLED_NAME, "1");
final Message message = new Message("Test".getBytes(), messageProperties);
spanInjector.inject(null, message);
final Map<String, Object> headers = message.getMessageProperties().getHeaders();
Assert.assertEquals("1", headers.get(TraceMessageHeaders.SAMPLED_NAME));
}
示例12: testInjectWithTrackKeysSuccess
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
public void testInjectWithTrackKeysSuccess() {
final TraceKeys traceKeys = new TraceKeys();
final Collection<String> traceKeyMessageHeaders = Arrays.asList("CUSTOM_HEADER", "NULL_HEADER");
final TraceKeys.Message traceKeyMessage = new TraceKeys.Message();
traceKeyMessage.setHeaders(traceKeyMessageHeaders);
traceKeys.setMessage(traceKeyMessage);
final AmqpMessagingSpanInjector spanInjector = new AmqpMessagingSpanInjector(traceKeys);
final Span span =
Span.builder().spanId(Span.hexToId("123")).traceId(Span.hexToId("456")).build();
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setHeader("CUSTOM_HEADER", "Custom header value");
messageProperties.setHeader("NULL_HEADER", null);
final Message message = new Message("Test".getBytes(), messageProperties);
spanInjector.inject(span, message);
final Map<String, Object> headers = message.getMessageProperties().getHeaders();
Assert.assertEquals("1", headers.get(TraceMessageHeaders.SAMPLED_NAME));
Assert.assertEquals("0000000000000123", headers.get(TraceMessageHeaders.SPAN_ID_NAME));
Assert.assertEquals("0000000000000456", headers.get(TraceMessageHeaders.TRACE_ID_NAME));
Assert.assertEquals(6, headers.size());
Assert.assertEquals("Custom header value", span.tags().get("message/custom_header"));
Assert.assertEquals("null", span.tags().get("message/null_header"));
}
示例13: testJoinTraceWithoutParentSuccess
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
public void testJoinTraceWithoutParentSuccess() {
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setHeader(TraceMessageHeaders.TRACE_ID_NAME, "123");
messageProperties.setHeader(TraceMessageHeaders.SPAN_ID_NAME, "456");
final Message message = new Message("Test".getBytes(), messageProperties);
final Span span = spanExtractor.joinTrace(message);
Assert.assertEquals("0000000000000123", span.traceIdString());
Assert.assertEquals("0000000000000456", Span.idToHex(span.getSpanId()));
}
示例14: testJoinTraceWithParentSuccess
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
public void testJoinTraceWithParentSuccess() {
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setHeader(TraceMessageHeaders.TRACE_ID_NAME, "123");
messageProperties.setHeader(TraceMessageHeaders.SPAN_ID_NAME, "456");
messageProperties.setHeader(TraceMessageHeaders.PARENT_ID_NAME, "111");
final Message message = new Message("Test".getBytes(), messageProperties);
final Span span = spanExtractor.joinTrace(message);
Assert.assertEquals("0000000000000123", span.traceIdString());
Assert.assertEquals("0000000000000456", Span.idToHex(span.getSpanId()));
Assert.assertEquals("0000000000000111", Span.idToHex(span.getParents().get(0)));
}
示例15: sendEvent
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
public void sendEvent(String apiKey, String channel, byte[] payload) {
try {
MessageProperties properties = new MessageProperties();
properties.setHeader(RabbitMQDataConfig.MSG_HEADER_APIKEY, apiKey);
properties.setHeader(RabbitMQDataConfig.MSG_HEADER_CHANNEL, channel);
Message message = new Message(payload, properties);
rabbitTemplate.convertAndSend("data.sub", message);
} catch (AmqpException ex) {
LOGGER.error("AmqpException while sending message to RabbitMQ...", ex);
}
}