本文整理匯總了Java中org.springframework.messaging.MessageChannel.send方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageChannel.send方法的具體用法?Java MessageChannel.send怎麽用?Java MessageChannel.send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.messaging.MessageChannel
的用法示例。
在下文中一共展示了MessageChannel.send方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doSend
import org.springframework.messaging.MessageChannel; //導入方法依賴的package包/類
@Override
protected final void doSend(MessageChannel channel, Message<?> message) {
Assert.notNull(channel, "'channel' is required");
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
if (accessor != null && accessor.isMutable()) {
accessor.setImmutable();
}
long timeout = this.sendTimeout;
boolean sent = (timeout >= 0 ? channel.send(message, timeout) : channel.send(message));
if (!sent) {
throw new MessageDeliveryException(message,
"failed to send message to channel '" + channel + "' within timeout: " + timeout);
}
}
示例2: afterSessionEnded
import org.springframework.messaging.MessageChannel; //導入方法依賴的package包/類
@Override
@SuppressWarnings("deprecation")
public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) {
this.decoders.remove(session.getId());
Principal principal = session.getPrincipal();
if (principal != null && this.userSessionRegistry != null) {
String userName = getSessionRegistryUserName(principal);
this.userSessionRegistry.unregisterSessionId(userName, session.getId());
}
Message<byte[]> message = createDisconnectMessage(session);
SimpAttributes simpAttributes = SimpAttributes.fromMessage(message);
try {
SimpAttributesContextHolder.setAttributes(simpAttributes);
if (this.eventPublisher != null) {
Principal user = session.getPrincipal();
publishEvent(new SessionDisconnectEvent(this, message, session.getId(), closeStatus, user));
}
outputChannel.send(message);
}
finally {
SimpAttributesContextHolder.resetAttributes();
simpAttributes.sessionCompleted();
}
}
示例3: logs
import org.springframework.messaging.MessageChannel; //導入方法依賴的package包/類
@RequestMapping(value = "/logs", method = RequestMethod.POST)
@ResponseBody
public String logs(@RequestBody String body) throws IOException {
// "application/logplex-1" does not conform to RFC5424.
// It leaves out STRUCTURED-DATA but does not replace it with
// a NILVALUE. To workaround this, we inject empty STRUCTURED-DATA.
String[] parts = body.split("router - ");
String log = parts[0] + "router - [] " + (parts.length > 1 ? parts[1] : "");
RFC6587SyslogDeserializer parser = new RFC6587SyslogDeserializer();
InputStream is = new ByteArrayInputStream(log.getBytes());
Map<String, ?> messages = parser.deserialize(is);
ObjectMapper mapper = new ObjectMapper();
MessageChannel toKafka = context.getBean("toKafka", MessageChannel.class);
String json = mapper.writeValueAsString(messages);
toKafka.send(new GenericMessage<>(json));
return "ok";
}
示例4: testIntegration
import org.springframework.messaging.MessageChannel; //導入方法依賴的package包/類
@Test
public void testIntegration() throws Exception {
MessageChannel producingChannel =
applicationContext.getBean("producingChannel", MessageChannel.class);
Map<String, Object> headers =
Collections.singletonMap(KafkaHeaders.TOPIC, SPRING_INTEGRATION_KAFKA_TOPIC);
LOGGER.info("sending 10 messages");
for (int i = 0; i < 10; i++) {
GenericMessage<String> message =
new GenericMessage<>("Hello Spring Integration Kafka " + i + "!", headers);
producingChannel.send(message);
LOGGER.info("sent message='{}'", message);
}
countDownLatchHandler.getLatch().await(10000, TimeUnit.MILLISECONDS);
assertThat(countDownLatchHandler.getLatch().getCount()).isEqualTo(0);
}
示例5: append
import org.springframework.messaging.MessageChannel; //導入方法依賴的package包/類
private void append(String name, Message<?> message) {
String key = (String) message.getHeaders().get(ROUTE_KEY);
if (message.getHeaders().getReplyChannel() instanceof MessageChannel) {
MessageChannel replyChannel = (MessageChannel) message.getHeaders()
.getReplyChannel();
replyChannel.send(message);
return;
}
Route route = new Route(key, name);
String path = route.getPath();
if (!queues.containsKey(path)) {
Bridge<Message<?>> flux = new Bridge<>();
queues.putIfAbsent(path, flux);
}
queues.get(path).send(message);
if (emitters.containsKey(path)) {
Set<SseEmitter> list = new HashSet<>(emitters.get(path));
for (SseEmitter emitter : list) {
try {
emitter.send(message.getPayload());
}
catch (IOException e) {
emitters.get(path).remove(emitter);
}
}
}
}
示例6: send
import org.springframework.messaging.MessageChannel; //導入方法依賴的package包/類
public boolean send(Message<?> message) throws Exception {
boolean result = false;
ExchangePattern pattern;
if (isExpectReply()) {
pattern = ExchangePattern.InOut;
} else {
pattern = ExchangePattern.InOnly;
}
Exchange inExchange = new DefaultExchange(getCamelContext(), pattern);
SpringIntegrationBinding.storeToCamelMessage(message, inExchange.getIn());
Exchange outExchange = getCamelTemplate().send(getCamelEndpointUri(), inExchange);
org.apache.camel.Message camelMsg = outExchange.hasOut() ? outExchange.getOut() : outExchange.getIn();
if (camelMsg.isFault()) {
result = true;
}
Message<?> response;
if (isExpectReply()) {
//Check the message header for the return address
response = SpringIntegrationBinding.storeToSpringIntegrationMessage(outExchange.getOut());
if (replyChannel == null) {
MessageChannel messageReplyChannel = (MessageChannel) message.getHeaders().get(MessageHeaders.REPLY_CHANNEL);
if (messageReplyChannel != null) {
result = messageReplyChannel.send(response);
} else {
throw new MessageDeliveryException(response, "Cannot resolve ReplyChannel from message: " + message);
}
} else {
result = replyChannel.send(response);
}
}
return result;
}
示例7: testSendingOneWayMessage
import org.springframework.messaging.MessageChannel; //導入方法依賴的package包/類
@Test
public void testSendingOneWayMessage() throws Exception {
MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
resultEndpoint.expectedBodiesReceived(MESSAGE_BODY);
MessageChannel outputChannel = getMandatoryBean(MessageChannel.class, "outputChannel");
outputChannel.send(new GenericMessage<Object>(MESSAGE_BODY));
assertMockEndpointsSatisfied();
}
示例8: testSendingOneWayMessage
import org.springframework.messaging.MessageChannel; //導入方法依賴的package包/類
@Test
public void testSendingOneWayMessage() throws Exception {
MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
resultEndpoint.expectedBodiesReceived(MESSAGE_BODY);
MessageChannel outputChannel = getMandatoryBean(MessageChannel.class, "channelA");
outputChannel.send(new GenericMessage<Object>(MESSAGE_BODY));
assertMockEndpointsSatisfied();
}
示例9: main
import org.springframework.messaging.MessageChannel; //導入方法依賴的package包/類
public static void main (String[] args){
AbstractApplicationContext context = new ClassPathXmlApplicationContext("/HelloWorldDemo.xml",App.class);
MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);
PollableChannel outputChannel = context.getBean("outputChannel", PollableChannel.class);
inputChannel.send(new GenericMessage<String>("World Mundo da Integração"));
logger.info("==> HelloWorldDemo: " + outputChannel.receive(0).getPayload());
context.close();
}