本文整理了Java中io.eventuate.tram.messaging.common.Message.getHeader()
方法的一些代码示例,展示了Message.getHeader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getHeader()
方法的具体详情如下:
包路径:io.eventuate.tram.messaging.common.Message
类名称:Message
方法名:getHeader
暂无
代码示例来源:origin: eventuate-tram/eventuate-tram-core
@Override
public String get(String key) {
return message.getHeader(key).orElse(null);
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
protected void sendMessage(String id, String destination, Message message, MessageSender messageSender) {
if (id == null) {
if (!message.getHeader(Message.ID).isPresent())
throw new IllegalArgumentException("message needs an id");
} else {
message.getHeaders().put(Message.ID, id);
}
message.getHeaders().put(Message.DESTINATION, destination);
message.getHeaders().put(Message.DATE, HttpDateHeaderFormatUtil.nowAsHttpDateString());
preSend(message);
try {
messageSender.send(message);
postSend(message, null);
} catch (RuntimeException e) {
postSend(message, e);
throw e;
}
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
public void messageHandler(Message message) {
logger.trace("Received message {} {}", commandDispatcherId, message);
Optional<CommandHandler> possibleMethod = commandHandlers.findTargetMethod(message);
if (!possibleMethod.isPresent()) {
throw new RuntimeException("No method for " + message);
}
CommandHandler m = possibleMethod.get();
Object param = convertPayload(m, message.getPayload());
Map<String, String> correlationHeaders = correlationHeaders(message.getHeaders());
Map<String, String> pathVars = getPathVars(message, m);
Optional<String> defaultReplyChannel = message.getHeader(CommandMessageHeaders.REPLY_TO);
List<Message> replies;
try {
CommandMessage cm = new CommandMessage(message.getId(), param, correlationHeaders, message);
replies = invoke(m, cm, pathVars);
logger.trace("Generated replies {} {} {}", commandDispatcherId, message, replies);
} catch (Exception e) {
logger.trace("Generated error {} {} {}", commandDispatcherId, message, e.getClass().getName());
handleException(message, param, m, e, pathVars, defaultReplyChannel);
return;
}
if (replies != null) {
publish(correlationHeaders, replies, defaultReplyChannel);
} else {
logger.trace("Null replies - not publishling");
}
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
public boolean containsReplyTo(String messageId) {
for (Message m : messages.toArray(new Message[0])) {
if (m.getHeader(ReplyMessageHeaders.IN_REPLY_TO).map(x -> x.equals(messageId)).orElse(false))
return true;
}
return false;
}
代码示例来源:origin: eventuate-tram/eventuate-tram-sagas
private Boolean isReplyForThisSagaType(Message message) {
return message.getHeader(SagaReplyHeaders.REPLY_SAGA_TYPE).map(x -> x.equals(getSagaType())).orElse(false);
}
代码示例来源:origin: io.eventuate.tram.sagas/eventuate-jpa-sagas-framework
private Boolean isReplyForThisSagaType(Message message) {
return message.getHeader(SagaReplyHeaders.REPLY_SAGA_TYPE).map(x -> x.equals(getSagaType())).orElse(false);
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
private boolean resourceMatches(Message message) {
return !resource.isPresent() || message.getHeader(CommandMessageHeaders.RESOURCE).map(m -> resourceMatches(m, resource.get())).orElse(false);
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
public <C extends DomainEvent> void assertDomainEventPublished(String channel, Class<C> expectedDomainEventClass) {
validateChannel(channel);
Eventually.eventually(() -> {
List<Message> messages = getMessages();
if (messages.stream()
.noneMatch(m -> m.getHeader(EventMessageHeaders.EVENT_TYPE).map(ct -> ct.equals(expectedDomainEventClass.getName())).orElse(false)))
fail(String.format("Cannot find domain eventmessage of type %s in %s", expectedDomainEventClass.getName(), messages));
});
}
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
public <C extends Command> void assertCommandMessageSent(String channel, Class<C> expectedCommandClass) {
validateChannel(channel);
Eventually.eventually(() -> {
List<Message> messages = getMessages();
if (messages.stream()
.noneMatch(m -> m.getHeader(CommandMessageHeaders.COMMAND_TYPE).map(ct -> ct.equals(expectedCommandClass.getName())).orElse(false)))
fail(String.format("Cannot find command message of type %s in %s", expectedCommandClass.getName(), messages));
});
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
private Map<String, String> getPathVars(Message message, CommandHandler handler) {
return handler.getResource().flatMap( res -> {
ResourcePathPattern r = ResourcePathPattern.parse(res);
return message.getHeader(CommandMessageHeaders.RESOURCE).map(h -> {
ResourcePath mr = ResourcePath.parse(h);
return r.getPathVariableValues(mr);
});
}).orElse(EMPTY_MAP);
}
代码示例来源:origin: eventuate-tram/eventuate-tram-sagas
private void handleReply(Message message) {
if (!isReplyForThisSagaType(message))
return;
logger.debug("Handle reply: {}", message);
String sagaId = message.getRequiredHeader(SagaReplyHeaders.REPLY_SAGA_ID);
String sagaType = message.getRequiredHeader(SagaReplyHeaders.REPLY_SAGA_TYPE);
SagaInstance sagaInstance = sagaInstanceRepository.find(sagaType, sagaId);
Data sagaData = SagaDataSerde.deserializeSagaData(sagaInstance.getSerializedSagaData());
message.getHeader(SagaReplyHeaders.REPLY_LOCKED).ifPresent(lockedTarget -> {
String destination = message.getRequiredHeader(CommandMessageHeaders.inReply(CommandMessageHeaders.DESTINATION));
sagaInstance.addDestinationsAndResources(singleton(new DestinationAndResource(destination, lockedTarget)));
});
String currentState = sagaInstance.getStateName();
logger.info("Current state={}", currentState);
SagaActions<Data> actions = getStateDefinition().handleReply(currentState, sagaData, message);
logger.info("Handled reply. Sending commands {}", actions.getCommands());
processActions(sagaId, sagaInstance, sagaData, actions);
}
代码示例来源:origin: io.eventuate.tram.sagas/eventuate-jpa-sagas-framework
message.getHeader(SagaReplyHeaders.REPLY_LOCKED).ifPresent(lockedTarget -> {
String destination = message.getRequiredHeader(CommandMessageHeaders.inReply(CommandMessageHeaders.DESTINATION));
sagaInstance.addDestinationsAndResources(singleton(new DestinationAndResource(destination, lockedTarget)));
内容来源于网络,如有侵权,请联系作者删除!