本文整理了Java中io.eventuate.tram.messaging.common.Message.getHeaders()
方法的一些代码示例,展示了Message.getHeaders()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getHeaders()
方法的具体详情如下:
包路径:io.eventuate.tram.messaging.common.Message
类名称:Message
方法名:getHeaders
暂无
代码示例来源:origin: eventuate-tram/eventuate-tram-core
public MessageBuilder(Message message) {
this(message.getPayload());
this.headers = message.getHeaders();
}
代码示例来源:origin: eventuate-tram/eventuate-tram-sagas
@Override
public void stashMessage(String sagaType, String sagaId, String target, Message message) {
logger.debug("Stashing message from {} for {} : {}", sagaId, target, message);
jdbcTemplate.update(insertIntoSagaStashTableSql,
message.getRequiredHeader(Message.ID),
target,
sagaType,
sagaId,
JSonMapper.toJson(message.getHeaders()),
message.getPayload()
);
}
代码示例来源: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: io.eventuate.tram.sagas/eventuate-jpa-sagas-framework
@Override
public void stashMessage(String sagaType, String sagaId, String target, Message message) {
logger.debug("Stashing message from {} for {} : {}", sagaId, target, message);
jdbcTemplate.update(insertIntoSagaStashTableSql,
message.getRequiredHeader(Message.ID),
target,
sagaType,
sagaId,
JSonMapper.toJson(message.getHeaders()),
message.getPayload()
);
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
@Override
protected ContractVerifierMessage convert(Message m) {
return m == null ? null : contractVerifierMessaging.create(m.getPayload(), m.getHeaders());
}
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
public DomainEventHandlerUnitTestSupport publishes(DomainEvent event) {
DomainEventPublisher publisher = new DomainEventPublisherImpl((destination, message) -> {
String id = idGenerator.generateId().toString();
message.getHeaders().put(Message.ID, id);
handler.accept(message);
});
publisher.publish(aggregateType, aggregateId, Collections.singletonList(event));
return this;
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
private boolean headersMatch(Message message, Contract groovyDsl) {
Map<String, String> headers = message.getHeaders();
boolean matches = true;
for (Header it : groovyDsl.getInput().getMessageHeaders().getEntries()) {
String name = it.getName();
Object value = it.getClientValue();
Object valueInHeader = headers.get(name);
matches &= value instanceof Pattern ?
((Pattern) value).matcher(valueInHeader.toString()).matches() :
valueInHeader != null && valueInHeader.equals(value);
}
return matches;
}
}
代码示例来源:origin: eventuate-tram/eventuate-tram-sagas
public SagaUnitTestSupport failureReply() {
Failure reply = new Failure();
CommandReplyOutcome outcome = CommandReplyOutcome.FAILURE;
Message message = replyMessage(reply, outcome);
String id = genId();
message.getHeaders().put(Message.ID, id);
sagaManager.handleMessage(message);
return this;
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
private void addMessageTags(Span span, Message message) {
Map<String, String> copy = new HashMap<>(message.getHeaders());
MessageHeaderPropagation.removeAnyTraceHeaders(new MessageHeaderMapAccessor(copy), this.tracing.propagation().keys());
copy.forEach((key, value) -> span.tag("message." + key, value));
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
private void send(Message message) {
String table = eventuateSchema.qualifyTable("message");
jdbcTemplate.update(String.format("insert into %s(id, destination, headers, payload) values(?, ?, ?, ?)", table),
message.getId(),
message.getRequiredHeader(Message.DESTINATION),
JSonMapper.toJson(message.getHeaders()),
message.getPayload());
}
代码示例来源:origin: eventuate-tram/eventuate-tram-sagas
public SagaUnitTestSupport successReply() {
Success reply = new Success();
CommandReplyOutcome outcome = CommandReplyOutcome.SUCCESS;
Message message = replyMessage(reply, outcome);
String id = genId();
message.getHeaders().put(Message.ID, id);
sagaManager.handleMessage(message);
return this;
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
private void handleException(Message message, Object param,
CommandHandler commandHandler,
Throwable cause,
Map<String, String> pathVars,
Optional<String> defaultReplyChannel) {
Optional<CommandExceptionHandler> m = commandHandlers.findExceptionHandler(cause);
logger.info("Handler for {} is {}", cause.getClass(), m);
if (m.isPresent()) {
List<Message> replies = m.get().invoke(cause);
publish(correlationHeaders(message.getHeaders()), replies, defaultReplyChannel);
} else {
List<Message> replies = singletonList(MessageBuilder.withPayload(JSonMapper.toJson(new Failure())).build());
publish(correlationHeaders(message.getHeaders()), replies, defaultReplyChannel);
}
}
代码示例来源:origin: io.eventuate.tram.core/eventuate-tram-producer-jdbc
private void send(Message message) {
String table = eventuateSchema.qualifyTable("message");
jdbcTemplate.update(String.format("insert into %s(id, destination, headers, payload, creation_time) values(?, ?, ?, ?, %s)",
table,
currentTimeInMillisecondsSql),
message.getId(),
message.getRequiredHeader(Message.DESTINATION),
JSonMapper.toJson(message.getHeaders()),
message.getPayload());
}
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
@Override
public void send(String destination, Message message) {
String id = idGenerator.genId().asString();
message.getHeaders().put(Message.ID, id);
if (TransactionSynchronizationManager.isActualTransactionActive()) {
logger.info("Transaction active");
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
reallySend(destination, message);
}
});
} else {
logger.info("No transaction active");
reallySend(destination, message);
}
}
代码示例来源:origin: io.eventuate.tram.core/eventuate-tram-in-memory
@Override
public void send(String destination, Message message) {
String id = idGenerator.genId().asString();
message.getHeaders().put(Message.ID, id);
if (TransactionSynchronizationManager.isActualTransactionActive()) {
logger.info("Transaction active");
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
reallySend(destination, message);
}
});
} else {
logger.info("No transaction active");
reallySend(destination, message);
}
}
代码示例来源: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-sagas
private Message replyMessage(Object reply, CommandReplyOutcome outcome) {
return MessageBuilder
.withPayload(JSonMapper.toJson(reply))
.withHeader(ReplyMessageHeaders.REPLY_OUTCOME, outcome.name())
.withHeader(ReplyMessageHeaders.REPLY_TYPE, reply.getClass().getName())
.withExtraHeaders("", correlationHeaders(sentCommand.getMessage().getHeaders()))
.build();
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
public CommandMessageHandlerUnitTestSupport commandHandlers(CommandHandlers commandHandlers) {
this.dispatcher = new CommandDispatcher("mockCommandDispatcher-" + System.currentTimeMillis(),
commandHandlers,
DefaultChannelMapping.builder().build(),
(subscriberId, channels, handler) -> CommandMessageHandlerUnitTestSupport.this.handler = handler,
(destination, message) -> {
CommandMessageHandlerUnitTestSupport.this.replyDestination = destination;
CommandMessageHandlerUnitTestSupport.this.replyMessage = message;
}
);
dispatcher.initialize();
producer = new CommandProducerImpl((destination, message) -> {
String id = idGenerator.generateId().toString();
message.getHeaders().put(Message.ID, id);
handler.accept(message);
}, DefaultChannelMapping.builder().build());
return this;
}
代码示例来源:origin: eventuate-tram/eventuate-tram-sagas
public <T> SagaUnitTestSupport saga(Saga<T> saga, T sagaData) {
SagaInstanceRepository sagaInstanceRepository = new SagaInstanceRepository() {
private SagaInstance sagaInstance;
@Override
public void save(SagaInstance sagaInstance) {
sagaInstance.setId(SAGA_ID);
this.sagaInstance = sagaInstance;
}
@Override
public SagaInstance find(String sagaType, String sagaId) {
return sagaInstance;
}
@Override
public void update(SagaInstance sagaInstance) {
this.sagaInstance = sagaInstance;
}
};
CommandProducerImpl commandProducer = new CommandProducerImpl((destination, message) -> {
String id = genId();
message.getHeaders().put(Message.ID, id);
sentCommands.add(new MessageWithDestination(destination, message));
}, new DefaultChannelMapping(Collections.emptyMap()));
SagaCommandProducer sagaCommandProducer = new SagaCommandProducer(commandProducer);
MessageConsumer messageConsumer = null;
SagaLockManager sagaLockManager = null;
sagaManager = new SagaManagerImpl<>(saga, sagaInstanceRepository, commandProducer, messageConsumer, new DefaultChannelMapping(Collections.emptyMap()),
sagaLockManager, sagaCommandProducer);
sagaManager.create(sagaData);
return this;
}
代码示例来源:origin: eventuate-tram/eventuate-tram-core
private Optional<Message> process(Message message, Contract groovyDsl) {
MessageBuilder messageBuilder = MessageBuilder
.withPayload(BodyExtractor
.extractStubValueFrom(groovyDsl.getOutputMessage().getBody()));
if (groovyDsl.getOutputMessage().getHeaders() != null) {
for (Header entry : groovyDsl.getOutputMessage().getHeaders().getEntries()) {
messageBuilder.withHeader(entry.getName(), entry.getClientValue().toString());
}
}
messageBuilder.withExtraHeaders("", correlationHeaders(message.getHeaders()));
return Optional.of(messageBuilder.build());
}
内容来源于网络,如有侵权,请联系作者删除!