本文整理匯總了Java中org.springframework.messaging.MessageHandler類的典型用法代碼示例。如果您正苦於以下問題:Java MessageHandler類的具體用法?Java MessageHandler怎麽用?Java MessageHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MessageHandler類屬於org.springframework.messaging包,在下文中一共展示了MessageHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: messageSender
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@Bean
@ServiceActivator(inputChannel = "pubSubOutputChannel")
public MessageHandler messageSender(PubSubTemplate pubsubTemplate) {
PubSubMessageHandler adapter =
new PubSubMessageHandler(pubsubTemplate, "exampleTopic");
adapter.setPublishCallback(new ListenableFutureCallback<String>() {
@Override
public void onFailure(Throwable ex) {
LOGGER.info("There was an error sending the message.");
}
@Override
public void onSuccess(String result) {
LOGGER.info("Message was sent successfully.");
}
});
return adapter;
}
示例2: handler
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@Bean
@ServiceActivator(inputChannel = "mqttInputChannel")
public MessageHandler handler() {
return new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
if (raptorMessageHandlerWrapper != null) {
try {
DispatcherPayload payload = DispatcherPayload.parseJSON(message.getPayload().toString());
raptorMessageHandlerWrapper.handle(payload, message.getHeaders());
} catch (Exception e) {
throw new MessagingException("Exception handling message", e);
}
}
}
};
}
示例3: run
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@Override
public void run(ApplicationArguments args) throws Exception {
logger.info("Consumer running with binder {}", binder);
SubscribableChannel consumerChannel = new ExecutorSubscribableChannel();
consumerChannel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
messagePayload = (String) message.getPayload();
logger.info("Received message: {}", messagePayload);
}
});
String group = null;
if (args.containsOption("group")) {
group = args.getOptionValues("group").get(0);
}
binder.bindConsumer(ConsulBinderTests.BINDING_NAME, group, consumerChannel,
new ConsumerProperties());
isBound = true;
}
示例4: amqpChannelAdapter
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@ServiceActivator(inputChannel = Sink.INPUT)
@Bean
public MessageHandler amqpChannelAdapter(ConnectionFactory rabbitConnectionFactory) {
AmqpOutboundEndpoint handler = new AmqpOutboundEndpoint(rabbitTemplate(rabbitConnectionFactory));
DefaultAmqpHeaderMapper mapper = new DefaultAmqpHeaderMapper();
mapper.setRequestHeaderNames(this.properties.getMappedRequestHeaders());
handler.setHeaderMapper(mapper);
handler.setDefaultDeliveryMode(this.properties.getPersistentDeliveryMode()
? MessageDeliveryMode.PERSISTENT
: MessageDeliveryMode.NON_PERSISTENT);
if (this.properties.getExchangeExpression() == null) {
handler.setExchangeName(this.properties.getExchange());
}
else {
handler.setExpressionExchangeName(this.properties.getExchangeExpression());
}
if (this.properties.getRoutingKeyExpression() == null) {
handler.setRoutingKey(this.properties.getRoutingKey());
}
else {
handler.setExpressionRoutingKey(this.properties.getRoutingKeyExpression());
}
return handler;
}
示例5: createProducerMessageHandler
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@Override
protected MessageHandler createProducerMessageHandler(ProducerDestination destination,
ExtendedProducerProperties<KinesisProducerProperties> producerProperties, MessageChannel errorChannel) {
KinesisMessageHandler kinesisMessageHandler = new KinesisMessageHandler(this.amazonKinesis);
kinesisMessageHandler.setSync(producerProperties.getExtension().isSync());
kinesisMessageHandler.setSendTimeout(producerProperties.getExtension().getSendTimeout());
kinesisMessageHandler.setStream(destination.getName());
if (producerProperties.isPartitioned()) {
kinesisMessageHandler
.setPartitionKeyExpressionString("'partitionKey-' + headers." + BinderHeaders.PARTITION_HEADER);
}
kinesisMessageHandler.setFailureChannel(errorChannel);
kinesisMessageHandler.setBeanFactory(getBeanFactory());
return kinesisMessageHandler;
}
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-aws-kinesis,代碼行數:18,代碼來源:KinesisMessageChannelBinder.java
示例6: stompBrokerRelayMessageHandler
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@Bean
public AbstractBrokerMessageHandler stompBrokerRelayMessageHandler() {
StompBrokerRelayMessageHandler handler = getBrokerRegistry().getStompBrokerRelay(brokerChannel());
if (handler == null) {
return new NoOpBrokerMessageHandler();
}
Map<String, MessageHandler> subscriptions = new HashMap<String, MessageHandler>(1);
String destination = getBrokerRegistry().getUserDestinationBroadcast();
if (destination != null) {
subscriptions.put(destination, userDestinationMessageHandler());
}
destination = getBrokerRegistry().getUserRegistryBroadcast();
if (destination != null) {
subscriptions.put(destination, userRegistryMessageHandler());
}
handler.setSystemSubscriptions(subscriptions);
return handler;
}
示例7: systemSubscription
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@Test
public void systemSubscription() throws Exception {
MessageHandler handler = mock(MessageHandler.class);
this.brokerRelay.setSystemSubscriptions(Collections.singletonMap("/topic/foo", handler));
this.brokerRelay.start();
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.CONNECTED);
accessor.setLeaveMutable(true);
MessageHeaders headers = accessor.getMessageHeaders();
this.tcpClient.handleMessage(MessageBuilder.createMessage(new byte[0], headers));
assertEquals(2, this.tcpClient.getSentMessages().size());
assertEquals(StompCommand.CONNECT, this.tcpClient.getSentHeaders(0).getCommand());
assertEquals(StompCommand.SUBSCRIBE, this.tcpClient.getSentHeaders(1).getCommand());
assertEquals("/topic/foo", this.tcpClient.getSentHeaders(1).getDestination());
Message<byte[]> message = message(StompCommand.MESSAGE, null, null, "/topic/foo");
this.tcpClient.handleMessage(message);
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
verify(handler).handleMessage(captor.capture());
assertSame(message, captor.getValue());
}
示例8: customChannels
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@Test
public void customChannels() {
loadBeanDefinitions("websocket-config-broker-customchannels.xml");
List<Class<? extends MessageHandler>> subscriberTypes =
Arrays.<Class<? extends MessageHandler>>asList(SimpAnnotationMethodMessageHandler.class,
UserDestinationMessageHandler.class, SimpleBrokerMessageHandler.class);
testChannel("clientInboundChannel", subscriberTypes, 3);
testExecutor("clientInboundChannel", 100, 200, 600);
subscriberTypes = Collections.singletonList(SubProtocolWebSocketHandler.class);
testChannel("clientOutboundChannel", subscriberTypes, 3);
testExecutor("clientOutboundChannel", 101, 201, 601);
subscriberTypes = Arrays.<Class<? extends MessageHandler>>asList(SimpleBrokerMessageHandler.class,
UserDestinationMessageHandler.class);
testChannel("brokerChannel", subscriberTypes, 1);
testExecutor("brokerChannel", 102, 202, 602);
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:MessageBrokerBeanDefinitionParserTests.java
示例9: doRegisterProducer
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
private Binding<MessageChannel> doRegisterProducer(final String name, MessageChannel moduleOutputChannel,
ProducerProperties properties) {
Assert.isInstanceOf(SubscribableChannel.class, moduleOutputChannel);
MessageHandler handler = new SendingHandler(name, properties);
EventDrivenConsumer consumer = new EventDrivenConsumer((SubscribableChannel) moduleOutputChannel, handler);
consumer.setBeanFactory(this.getBeanFactory());
consumer.setBeanName("outbound." + name);
consumer.afterPropertiesSet();
DefaultBinding<MessageChannel> producerBinding =
new DefaultBinding<>(name, null, moduleOutputChannel, consumer);
String[] requiredGroups = properties.getRequiredGroups();
if (!ObjectUtils.isEmpty(requiredGroups)) {
for (String group : requiredGroups) {
this.redisOperations.boundZSetOps(CONSUMER_GROUPS_KEY_PREFIX + name).incrementScore(group, 1);
}
}
consumer.start();
return producerBinding;
}
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-redis,代碼行數:20,代碼來源:RedisMessageChannelBinder.java
示例10: createProducerMessageHandler
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@Override
protected MessageHandler createProducerMessageHandler(List<TopicInfo> destinations,
ExtendedProducerProperties<PubSubProducerProperties> producerProperties)
throws Exception {
PubSubMessageHandler handler = null;
if (producerProperties.getExtension().isBatchEnabled()) {
handler = new BatchingPubSubMessageHandler(resourceManager,
producerProperties, destinations);
((BatchingPubSubMessageHandler) handler)
.setConcurrency(producerProperties.getExtension().getConcurrency());
}
else {
handler = new SimplePubSubMessageHandler(resourceManager, producerProperties,
destinations);
}
resourceManager.createRequiredMessageGroups(destinations, producerProperties);
return handler;
}
開發者ID:viniciusccarvalho,項目名稱:spring-cloud-stream-binder-pubsub,代碼行數:22,代碼來源:PubSubMessageChannelBinder.java
示例11: datasetSinkMessageHandler
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@Bean
@ServiceActivator(inputChannel = "toSink")
public MessageHandler datasetSinkMessageHandler(final DatasetOperations datasetOperations) {
return new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
Object payload = message.getPayload();
if (payload instanceof Collection<?>) {
Collection<?> payloads = (Collection<?>) payload;
logger.debug("Writing a collection of {} POJOs" + payloads.size());
datasetOperations.write((Collection<?>) message.getPayload());
}
else {
// This should never happen since message handler is fronted by an aggregator
throw new IllegalStateException("Expected a collection of POJOs but received " +
message.getPayload().getClass().getName());
}
}
};
}
示例12: amqpChannelAdapter
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@ServiceActivator(inputChannel = Sink.INPUT)
@Bean
public MessageHandler amqpChannelAdapter(ConnectionFactory rabbitConnectionFactory) {
AmqpOutboundEndpointSpec handler = Amqp.outboundAdapter(rabbitTemplate(rabbitConnectionFactory))
.mappedRequestHeaders(properties.getMappedRequestHeaders())
.defaultDeliveryMode(properties.getPersistentDeliveryMode() ? MessageDeliveryMode.PERSISTENT
: MessageDeliveryMode.NON_PERSISTENT);
Expression exchangeExpression = this.properties.getExchangeExpression();
if (exchangeExpression != null) {
handler.exchangeNameExpression(exchangeExpression);
}
else {
handler.exchangeName(this.properties.getExchange());
}
Expression routingKeyExpression = this.properties.getRoutingKeyExpression();
if (routingKeyExpression != null) {
handler.routingKeyExpression(routingKeyExpression);
}
else {
handler.routingKey(this.properties.getRoutingKey());
}
return handler.get();
}
示例13: amazonS3MessageHandler
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@Bean
@ServiceActivator(inputChannel = Sink.INPUT)
public MessageHandler amazonS3MessageHandler(AmazonS3 amazonS3, ResourceIdResolver resourceIdResolver,
AmazonS3SinkProperties s3SinkProperties) {
S3MessageHandler s3MessageHandler;
if (s3SinkProperties.getBucket() != null) {
s3MessageHandler = new S3MessageHandler(amazonS3, s3SinkProperties.getBucket());
}
else {
s3MessageHandler = new S3MessageHandler(amazonS3, s3SinkProperties.getBucketExpression());
}
s3MessageHandler.setResourceIdResolver(resourceIdResolver);
s3MessageHandler.setKeyExpression(s3SinkProperties.getKeyExpression());
if (s3SinkProperties.getAcl() != null) {
s3MessageHandler.setObjectAclExpression(new ValueExpression<>(s3SinkProperties.getAcl()));
}
else {
s3MessageHandler.setObjectAclExpression(s3SinkProperties.getAclExpression());
}
s3MessageHandler.setUploadMetadataProvider(this.uploadMetadataProvider);
s3MessageHandler.setProgressListener(this.s3ProgressListener);
return s3MessageHandler;
}
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-app-starters,代碼行數:24,代碼來源:AmazonS3SinkConfiguration.java
示例14: redisSinkMessageHandler
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@Bean
@ServiceActivator(inputChannel = Sink.INPUT)
public MessageHandler redisSinkMessageHandler() {
if (this.redisSinkProperties.isKey()) {
RedisStoreWritingMessageHandler redisStoreWritingMessageHandler = new RedisStoreWritingMessageHandler(
this.redisConnectionFactory);
redisStoreWritingMessageHandler.setKeyExpression(this.redisSinkProperties.keyExpression());
return redisStoreWritingMessageHandler;
}
else if (this.redisSinkProperties.isQueue()) {
return new RedisQueueOutboundChannelAdapter(this.redisSinkProperties.queueExpression(),
this.redisConnectionFactory);
}
else { // must be topic
RedisPublishingMessageHandler redisPublishingMessageHandler = new RedisPublishingMessageHandler(
this.redisConnectionFactory);
redisPublishingMessageHandler.setTopicExpression(this.redisSinkProperties.topicExpression());
return redisPublishingMessageHandler;
}
}
示例15: cassandraSinkMessageHandler
import org.springframework.messaging.MessageHandler; //導入依賴的package包/類
@Bean
@ServiceActivator(inputChannel = "toSink")
public MessageHandler cassandraSinkMessageHandler() {
CassandraMessageHandler<?> cassandraMessageHandler =
this.cassandraSinkProperties.getQueryType() != null
? new CassandraMessageHandler<>(this.template, this.cassandraSinkProperties.getQueryType())
: new CassandraMessageHandler<>(this.template);
cassandraMessageHandler.setProducesReply(false);
if (this.cassandraSinkProperties.getConsistencyLevel() != null
|| this.cassandraSinkProperties.getRetryPolicy() != null
|| this.cassandraSinkProperties.getTtl() > 0) {
cassandraMessageHandler.setWriteOptions(
new WriteOptions(this.cassandraSinkProperties.getConsistencyLevel(),
this.cassandraSinkProperties.getRetryPolicy(), this.cassandraSinkProperties.getTtl()));
}
if (StringUtils.hasText(this.cassandraSinkProperties.getIngestQuery())) {
cassandraMessageHandler.setIngestQuery(this.cassandraSinkProperties.getIngestQuery());
}
else if (this.cassandraSinkProperties.getStatementExpression() != null) {
cassandraMessageHandler.setStatementExpression(this.cassandraSinkProperties.getStatementExpression());
}
return cassandraMessageHandler;
}
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-app-starters,代碼行數:24,代碼來源:CassandraSinkConfiguration.java