本文整理汇总了Java中org.springframework.messaging.support.MessageBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java MessageBuilder.build方法的具体用法?Java MessageBuilder.build怎么用?Java MessageBuilder.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.messaging.support.MessageBuilder
的用法示例。
在下文中一共展示了MessageBuilder.build方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preSend
import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
Span parentSpan = getTracer().isTracing() ? getTracer().getCurrentSpan()
: buildSpan(message);
String name = getMessageChannelName(channel);
Span span = startSpan(parentSpan, name, message);
MessageBuilder<?> messageBuilder = MessageBuilder.fromMessage(message);
if (message.getHeaders().containsKey(MESSAGE_SENT_FROM_CLIENT)) {
span.logEvent(Span.SERVER_RECV);
} else {
span.logEvent(Span.CLIENT_SEND);
messageBuilder.setHeader(MESSAGE_SENT_FROM_CLIENT, true);
}
getSpanInjector().inject(span, messageBuilder);
return messageBuilder.build();
}
示例2: nativeSpanHeadersAdded
import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Test
public void nativeSpanHeadersAdded() {
Span span = Span.builder().name("http:foo").spanId(1L).traceId(2L).build();
MessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
Message<String> messageToBuild = MessageBuilder.createMessage("Hello World",
accessor.getMessageHeaders());
MessageBuilder<String> messageBuilder = MessageBuilder
.fromMessage(messageToBuild);
this.messagingSpanInjector.inject(span, messageBuilder);
Message<String> message = messageBuilder.build();
assertThat(message.getHeaders())
.containsKey(NativeMessageHeaderAccessor.NATIVE_HEADERS);
MessageHeaderAccessor natives = NativeMessageHeaderAccessor
.getMutableAccessor(message);
assertThat(natives.getMessageHeaders()).containsKey(Span.SPAN_ID_NAME);
}
示例3: poll
import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
private Message<Collection<Object>> poll(String channel, String key,
boolean requeue) {
List<Object> list = new ArrayList<>();
List<Message<?>> messages = new ArrayList<>();
Bridge<Message<?>> queue = queues.get(new Route(key, channel).getPath());
if (queue != null) {
queue.receive().subscribe(message -> {
messages.add(message);
list.add(message.getPayload());
});
if (!requeue) {
queue.reset();
}
}
MessageBuilder<Collection<Object>> builder = MessageBuilder.withPayload(list);
if (!messages.isEmpty()) {
builder.copyHeadersIfAbsent(messages.get(0).getHeaders());
}
return builder.build();
}
示例4: doConvert
import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Override
protected Message<?> doConvert(Object payload, Map<String, Object> headers, MessagePostProcessor postProcessor) {
String content;
if (payload instanceof String) {
content = (String) payload;
} else {
// if payload not as string, use objectMapper change it.
try {
content = objectMapper.writeValueAsString(payload);
} catch (JsonProcessingException e) {
log.info("convert payload to String failed. payload:{}", payload);
throw new RuntimeException("convert to payload to String failed.", e);
}
}
MessageBuilder<?> builder = MessageBuilder.withPayload(content);
if (headers != null) {
builder.copyHeaders(headers);
}
builder.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN);
Message<?> message = builder.build();
if (postProcessor != null) {
message = postProcessor.postProcessMessage(message);
}
return message;
}
示例5: preSendClientSpan
import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
private Message<?> preSendClientSpan(Message<?> message) {
Span span = tracer.buildSpan((String) message.getHeaders()
.getOrDefault(SIMP_DESTINATION, UNKNOWN_DESTINATION))
.withTag(Tags.SPAN_KIND.getKey(), spanKind)
.withTag(Tags.COMPONENT.getKey(), WEBSOCKET)
.startManual();
MessageBuilder<?> messageBuilder = MessageBuilder.fromMessage(message)
.setHeader(OPENTRACING_SPAN, span);
tracer
.inject(span.context(), Format.Builtin.TEXT_MAP, new TextMapInjectAdapter(messageBuilder));
return messageBuilder.build();
}
示例6: toMessage
import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Override
public final Message<?> toMessage(Object payload, MessageHeaders headers, Object conversionHint) {
if (!canConvertTo(payload, headers)) {
return null;
}
payload = convertToInternal(payload, headers, conversionHint);
if (payload == null) {
return null;
}
MimeType mimeType = getDefaultContentType(payload);
if (headers != null) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(headers, MessageHeaderAccessor.class);
if (accessor != null && accessor.isMutable()) {
accessor.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType);
return MessageBuilder.createMessage(payload, accessor.getMessageHeaders());
}
}
MessageBuilder<?> builder = MessageBuilder.withPayload(payload);
if (headers != null) {
builder.copyHeaders(headers);
}
builder.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType);
return builder.build();
}
示例7: message
import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
private Message<byte[]> message(SimpMessageType messageType) {
MessageBuilder<byte[]> builder = MessageBuilder.withPayload(new byte[0]);
if (messageType != null) {
builder.setHeader(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER, messageType);
}
return builder.build();
}
示例8: inject
import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Override
public void inject(Span span, MessageBuilder<?> carrier) {
Message<?> initialMessage = carrier.build();
MessageHeaderAccessor accessor = MessageHeaderAccessor
.getMutableAccessor(initialMessage);
if (span == null) {
if (!Span.SPAN_SAMPLED
.equals(initialMessage.getHeaders().get(Span.SAMPLED_NAME))) {
accessor.setHeader(Span.SAMPLED_NAME, Span.SPAN_NOT_SAMPLED);
carrier.setHeaders(accessor);
return;
}
return;
}
Map<String, String> headers = new HashMap<>();
addHeader(headers, Span.TRACE_ID_NAME, Span.idToHex(span.getTraceId()));
addHeader(headers, Span.SPAN_ID_NAME, Span.idToHex(span.getSpanId()));
if (span.isExportable()) {
addAnnotations(this.traceKeys, initialMessage, span);
Long parentId = getFirst(span.getParents());
if (parentId != null) {
addHeader(headers, Span.PARENT_ID_NAME, Span.idToHex(parentId));
}
addHeader(headers, Span.SPAN_NAME_NAME, span.getName());
addHeader(headers, Span.PROCESS_ID_NAME, span.getProcessId());
addHeader(headers, Span.SAMPLED_NAME, Span.SPAN_SAMPLED);
}
else {
addHeader(headers, Span.SAMPLED_NAME, Span.SPAN_NOT_SAMPLED);
}
accessor.setHeader(SPAN_HEADER, span);
accessor.copyHeaders(headers);
if (accessor instanceof NativeMessageHeaderAccessor) {
NativeMessageHeaderAccessor nativeAccessor = (NativeMessageHeaderAccessor) accessor;
for (String name : headers.keySet()) {
nativeAccessor.setNativeHeader(name, headers.get(name));
}
}
carrier.setHeaders(accessor);
}
示例9: forPayload
import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
private static Message<?> forPayload(String metricName, Object payload) {
MessageBuilder<Object> builder = MessageBuilder.withPayload(payload);
builder.setHeader(METRIC_NAME, metricName);
return builder.build();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:6,代码来源:MetricMessage.java