当前位置: 首页>>代码示例>>Java>>正文


Java MessageHandler类代码示例

本文整理汇总了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;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:20,代码来源:SenderApplication.java

示例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);
                }
            }
        }
    };
}
 
开发者ID:raptorbox,项目名称:raptor,代码行数:18,代码来源:MqttConfiguration.java

示例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;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-consul,代码行数:22,代码来源:TestConsumer.java

示例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;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:25,代码来源:RabbitSinkConfiguration.java

示例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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:AbstractMessageBrokerConfiguration.java

示例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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:StompBrokerRelayMessageHandlerTests.java

示例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());
			}
		}
	};
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:hdfs,代码行数:22,代码来源:HdfsDatasetSinkConfiguration.java

示例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();
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:rabbit,代码行数:27,代码来源:RabbitSinkConfiguration.java

示例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;
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:21,代码来源:RedisSinkConfiguration.java

示例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


注:本文中的org.springframework.messaging.MessageHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。