本文整理汇总了Java中org.springframework.amqp.core.MessageProperties类的典型用法代码示例。如果您正苦于以下问题:Java MessageProperties类的具体用法?Java MessageProperties怎么用?Java MessageProperties使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageProperties类属于org.springframework.amqp.core包,在下文中一共展示了MessageProperties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTraceData
import org.springframework.amqp.core.MessageProperties; //导入依赖的package包/类
@Override
public TraceData getTraceData() {
MessageProperties messageProperties = message.getMessageProperties();
final String sampled = (String) messageProperties.getHeaders().get(Headers.Sampled.getName());
if (sampled != null) {
if (sampled.equals("0") || sampled.toLowerCase().equals("false")) {
return TraceData.builder().sample(false).build();
} else {
final String parentSpanId = (String) messageProperties.getHeaders().get(Headers.ParentSpanId.getName());
final String traceId = (String) messageProperties.getHeaders().get(Headers.TraceId.getName());
final String spanId = (String) messageProperties.getHeaders().get(Headers.SpanId.getName());
if (traceId != null && spanId != null) {
SpanId span = getSpanId(traceId, spanId, parentSpanId);
return TraceData.builder().sample(true).spanId(span).build();
}
}
}
return TraceData.builder().build();
}
示例2: call
import org.springframework.amqp.core.MessageProperties; //导入依赖的package包/类
/**
* @Title: call
* @Description: call类型,点对点发送接收消息
* @param topicRoutingKey
* @param serverName
* @param bodyMsg
* @param outTimeMillis
* @throws Exception 设定文件
* @return Map<String,Object> 返回类型
*/
public Map<String,Object> call(String topicRoutingKey,String serverName,Map<String,Object> bodyMsg,int outTimeMillis) throws Exception{
Map<String,Object> sendMsg = new HashMap<String,Object>();
sendMsg.put("mqkey",topicRoutingKey+"."+serverName);
sendMsg.put("mqtype","call");
sendMsg.put("mqbody",bodyMsg==null?new HashMap<String,Object>():bodyMsg);
String topicMessage = JSON.toJSONString(sendMsg, JsonFilter.filter);
Message message=new Message(topicMessage.getBytes("UTF-8"),new MessageProperties());
RabbitTemplate directTemplate =new RabbitTemplate();
directTemplate.setConnectionFactory(connectionFactory);
directTemplate.setExchange(PropertyLoader.MQ_EXCHANGE);
directTemplate.setReplyTimeout(outTimeMillis);
Message reply=directTemplate.sendAndReceive(topicRoutingKey,message);
if(reply==null){
throw new Exception("waitting rabbitmq response timeout");
}
String body=new String(reply.getBody(),"UTF-8");
Map<String,Object> reqMsgMap =JSON.parseObject(body,new TypeReference<Map<String, Object>>(){});
LOG.info("back :"+reqMsgMap);
reqMsgMap =JSON.parseObject(reqMsgMap.get("mqbody").toString(),new TypeReference<Map<String, Object>>(){});
return reqMsgMap;
}
示例3: testInjectSuccess
import org.springframework.amqp.core.MessageProperties; //导入依赖的package包/类
@Test
public void testInjectSuccess() {
final AmqpMessagingSpanInjector spanInjector = new AmqpMessagingSpanInjector(new TraceKeys());
final Span span =
Span.builder().spanId(Span.hexToId("123")).traceId(Span.hexToId("456")).build();
final Message message = new Message("Test".getBytes(), new 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(4, headers.size());
}
示例4: testInjectWithParentIdSuccess
import org.springframework.amqp.core.MessageProperties; //导入依赖的package包/类
@Test
public void testInjectWithParentIdSuccess() {
final AmqpMessagingSpanInjector spanInjector = new AmqpMessagingSpanInjector(new TraceKeys());
final Span span =
Span.builder()
.parent(Span.hexToId("999"))
.spanId(Span.hexToId("123"))
.traceId(Span.hexToId("456"))
.build();
final Message message = new Message("Test".getBytes(), new MessageProperties());
spanInjector.inject(span, message);
final Map<String, Object> headers = message.getMessageProperties().getHeaders();
Assert.assertEquals("1", headers.get(TraceMessageHeaders.SAMPLED_NAME));
Assert.assertEquals("0000000000000999", headers.get(TraceMessageHeaders.PARENT_ID_NAME));
Assert.assertEquals("0000000000000123", headers.get(TraceMessageHeaders.SPAN_ID_NAME));
Assert.assertEquals("0000000000000456", headers.get(TraceMessageHeaders.TRACE_ID_NAME));
Assert.assertEquals(5, headers.size());
}
示例5: testInjectSpanNotExportableSuccess
import org.springframework.amqp.core.MessageProperties; //导入依赖的package包/类
@Test
public void testInjectSpanNotExportableSuccess() {
final AmqpMessagingSpanInjector spanInjector = new AmqpMessagingSpanInjector(new TraceKeys());
final Message message = new Message("Test".getBytes(), new MessageProperties());
final Span span =
Span.builder()
.exportable(false)
.spanId(Span.hexToId("123"))
.traceId(Span.hexToId("456"))
.build();
spanInjector.inject(span, message);
final Map<String, Object> headers = message.getMessageProperties().getHeaders();
Assert.assertEquals("0", 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(4, headers.size());
}
示例6: aspectInvokeSendSuccess
import org.springframework.amqp.core.MessageProperties; //导入依赖的package包/类
@Test
public void aspectInvokeSendSuccess() throws Throwable {
Assert.assertNotNull(amqpTemplate);
final Message message = new Message("body-send".getBytes(), new MessageProperties());
amqpTemplate.send(message);
verify(amqpMessagingSpanManager).beforeSend(eq(message), eq("amqp://my-default-exchange/*"));
verify(amqpMessagingSpanManager).afterSend(eq(null));
}
示例7: 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());
}
示例8: testBeforeSendWithCurrentSpanOnClientSendFromMessage
import org.springframework.amqp.core.MessageProperties; //导入依赖的package包/类
@Test
public void testBeforeSendWithCurrentSpanOnClientSendFromMessage() {
when(tracer.isTracing()).thenReturn(false);
final Span parentSpan = mock(Span.class, "parentSpan");
final Message message = new Message("Test".getBytes(), new 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.CLIENT_SEND));
}
示例9: 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));
}
示例10: 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));
}
示例11: toJavaType
import org.springframework.amqp.core.MessageProperties; //导入依赖的package包/类
@Override
public JavaType toJavaType(MessageProperties properties) {
String classTypeId = retrieveHeader(properties, getClassIdFieldName());
String contentTypeId = retrieveHeader(properties, getContentClassIdFieldName());
String keyTypeId = retrieveHeader(properties, getKeyClassIdFieldName());
if (StringUtils.isEmpty(contentTypeId)) {
return JSON_OBJECT_MAPPER.getTypeFactory().constructType(forName(classTypeId));
}
if (StringUtils.isEmpty(keyTypeId)) {
return JSON_OBJECT_MAPPER.getTypeFactory().constructParametrizedType(forName(classTypeId), forName(classTypeId), forName(contentTypeId));
} else {
return JSON_OBJECT_MAPPER.getTypeFactory().constructParametrizedType(forName(classTypeId), null, forName(keyTypeId), forName(contentTypeId));
}
}
示例12: onConfigPub
import org.springframework.amqp.core.MessageProperties; //导入依赖的package包/类
@RabbitListener(queues = "mgmt.config.pub")
public void onConfigPub(Message message) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("A message has arrived -> " + message.toString());
MessageProperties properties = message.getMessageProperties();
if (properties == null || properties.getHeaders().isEmpty()) {
LOGGER.error("MessageProperties is empty");
return;
}
String apiKey = (String) properties.getHeaders().get(RabbitMQDataConfig.MSG_HEADER_APIKEY);
if (!StringUtils.hasText(apiKey)) {
LOGGER.error("Apikey not found.");
return;
}
Device device = deviceRegisterService.findByApiKey(apiKey);
if (!Optional.ofNullable(device).isPresent()) {
LOGGER.error("Device does not exist");
return;
}
ServiceResponse<String> serviceResponse = deviceConfigSetupService
.findByModelAndLocation(device.getTenant(),
device.getApplication(),
device.getDeviceModel(),
device.getLocation());
String config = Optional.ofNullable(serviceResponse.getResult()).orElse("{ }");
rabbitGateway.sendConfig(apiKey, config);
}
示例13: 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);
}
示例14: 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());
}
示例15: onMessage
import org.springframework.amqp.core.MessageProperties; //导入依赖的package包/类
@Override
public void onMessage(org.springframework.amqp.core.Message message) {
StandardLogger logger = LoggerUtil.getStandardLogger();
String logtag = "EngineDriver.T" + Thread.currentThread().getId() + " - ";
try {
String txt = new String(message.getBody());
if (logger.isDebugEnabled()) {
logger.debug("JMS Spring Rabbit InternalEvent Listener receives request: " + txt);
}
logger.info(logtag + "starts processing");
String messageId = null;
MessageProperties props = message.getMessageProperties();
if (message.getMessageProperties() != null && props.getCorrelationId() != null)
messageId = new String (props.getCorrelationId());
ProcessEngineDriver driver = new ProcessEngineDriver();
driver.processEvents(messageId, txt);
} catch (Throwable e) { // only possible when failed to get ProcessManager ejb
logger.severeException(logtag + "process exception " + e.getMessage(), e);
}
}