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


Java ServiceActivator类代码示例

本文整理汇总了Java中org.springframework.integration.annotation.ServiceActivator的典型用法代码示例。如果您正苦于以下问题:Java ServiceActivator类的具体用法?Java ServiceActivator怎么用?Java ServiceActivator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServiceActivator类属于org.springframework.integration.annotation包,在下文中一共展示了ServiceActivator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: messageSender

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的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: restOutbound

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的package包/类
@ServiceActivator(inputChannel = "outbound-rest", outputChannel = "mark-outboud")
public String restOutbound(Message<?> msg) {
	try {
		ExportString exportString = (ExportString) msg.getPayload();
		logger.debug("message arrived at REST outbound sender: " + exportString.getEventId());
		Addressable addressable = exportString.getRegistration().getAddressable();
		String uri = addressable.getAddress() + ":" + addressable.getPort() + addressable.getPath();
		HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler(uri);
		handler.setHttpMethod(HttpMethod.POST);
		handler.setExpectReply(false);
		Message<String> message = MessageBuilder.withPayload(exportString.getEventString()).build();
		handler.handleMessage(message);
		logger.info("message sent to REST address:  " + uri + " : " + exportString.getEventId());
		return exportString.getEventId();
	} catch (Exception e) {
		logger.error("Problem with sending message via REST: " + e.getMessage());
		return null;
	}
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:20,代码来源:RESTOutboundServiceActivator.java

示例3: zmqOutbound

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的package包/类
@ServiceActivator(inputChannel = "outbound-zmq", outputChannel = "mark-outboud")
public String zmqOutbound(Message<?> msg) {
	try {
		ExportString exportString = (ExportString) msg.getPayload();
		logger.debug("message arrived at 0MQ outbound sender: " + exportString.getEventId());
		// today, for ZMQ, subscribers will listen to pre-subscribed EdgeX
		// ZMQ outbound port.
		// TODO - someday, reverse the direction and allow clients to set up
		// individual ZMQ port to publish out of
		logger.debug(".....sending: " + exportString.getEventString());
		sendor.sendEventMessage(exportString.getEventString());
		// logger.error("--->" + exportString.getEventId() + " [email protected]
		// " + System.currentTimeMillis());
		logger.info("message sent via 0MQ " + exportString.getEventId());
		return exportString.getEventId();
	} catch (Exception e) {
		logger.error("Problem with sending message via 0MQ: " + e.getMessage());
	}
	return null;
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:21,代码来源:ZMQOutboundServiceActivator.java

示例4: mqttOutbound

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的package包/类
@ServiceActivator(inputChannel = "outbound-iotcore", outputChannel = "mark-outboud")
public String mqttOutbound(Message<?> msg) {
	try {
		ExportString payload = (ExportString) msg.getPayload();
		logger.debug("message arrived at IoT Core MQTT outbound sender: " + payload.getEventId());
		Addressable addressable = payload.getRegistration().getAddressable();
		if (addressable != null) {
			// TODO - cache and reuse clients per clientId
			// String clientId = addressable.getPublisher();

			if (sender == null) {
				sender = new IotCoreMQTTSender(addressable, privateKeyFile, algorithm, 0, 600);
			}
			boolean ok = sender.sendMessage(payload.getEventString().getBytes());
			if (!ok) throw new Exception("error while sending message");
			logger.info("message sent to IoT Core MQTT broker:  " + payload.getRegistration().getAddressable() + " : " + payload.getEventId());
			return payload.getEventId();
		} else {
			logger.error("No MQTT address information provided with registration.  Event message not sent for client.");
		}
	} catch (Exception e) {
		logger.error("Problem when sending message via MQTT: " + e.getMessage());
	}
	return null;
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:26,代码来源:IotCoreMQTTOutboundServiceActivator.java

示例5: mqttOutbound

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的package包/类
@ServiceActivator(inputChannel = "outbound-azure", outputChannel = "mark-outboud")
public String mqttOutbound(Message<?> msg) {
	try {
		ExportString exportString = (ExportString) msg.getPayload();
		logger.debug("message arrived at Azure MQTT outbound sender: " + exportString.getEventId());
		Addressable addressable = exportString.getRegistration().getAddressable();
		if (addressable != null) {
			// TODO - someday cache and reuse clients
			AzureMQTTSender sender = new AzureMQTTSender(exportString.getRegistration().getAddressable(),
					exportString.getDeviceId());
			sender.sendMessage(exportString.getEventString().getBytes());
			logger.info("message sent to Azure MQTT broker:  " + exportString.getRegistration().getAddressable()
					+ " : " + exportString.getEventId());
			return exportString.getEventId();
		} else
			logger.error(
					"No MQTT address information provided with registration.  Event message not sent for client.");
	} catch (Exception e) {
		logger.error("Problem with sending message via MQTT: " + e.getMessage());
	}
	return null;
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:23,代码来源:AzureMQTTOutboundServiceActivator.java

示例6: handler

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的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

示例7: amqpChannelAdapter

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的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

示例8: datasetSinkMessageHandler

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的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

示例9: amqpChannelAdapter

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的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

示例10: websocketSink

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的package包/类
@ServiceActivator(inputChannel = Sink.INPUT)
public void websocketSink(Message<?> message) {
	if (logger.isTraceEnabled()) {
		logger.trace(String.format("Handling message: %s", message));
	}

	SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message);
	headers.setMessageTypeIfNotSet(SimpMessageType.MESSAGE);
	String messagePayload = message.getPayload().toString();
	for (Channel channel : WebsocketSinkServer.channels) {
		if (logger.isTraceEnabled()) {
			logger.trace(String.format("Writing message %s to channel %s", messagePayload, channel.localAddress()));
		}

		channel.write(new TextWebSocketFrame(messagePayload));
		channel.flush();
	}

	if (traceEndpointEnabled) {
		addMessageToTraceRepository(message);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:23,代码来源:WebsocketSinkConfiguration.java

示例11: process

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的package包/类
@ServiceActivator(inputChannel=Sink.INPUT)
public void process(Message<?> message) {
	Object payload = message.getPayload();
	if (payload instanceof String) {
		try {
			payload = jsonToTupleTransformer.transformPayload(payload.toString());
		}
		catch (Exception e) {
			throw new MessageTransformationException(message, e.getMessage(), e);
		}
	}
	if (payload instanceof Tuple) {
		processTuple(computeMetricName(message), (Tuple) payload);
	}
	else {
		processPojo(computeMetricName(message), payload);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:19,代码来源:FieldValueCounterSinkConfiguration.java

示例12: amazonS3MessageHandler

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的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

示例13: redisSinkMessageHandler

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的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

示例14: cassandraSinkMessageHandler

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的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

示例15: process

import org.springframework.integration.annotation.ServiceActivator; //导入依赖的package包/类
@ServiceActivator(inputChannel = Sink.INPUT)
public void process(Message<?> message) {
	Object payload = message.getPayload();
	if (payload instanceof String) {
		try {
			payload = jsonToTupleTransformer.transformPayload(payload.toString());
		}
		catch (Exception e) {
			throw new MessageTransformationException(message, e.getMessage(), e);
		}
	}
	if (payload instanceof Tuple) {
		processTuple(computeMetricName(message), (Tuple) payload);
	}
	else {
		processPojo(computeMetricName(message), payload);
	}
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:field-value-counter,代码行数:19,代码来源:FieldValueCounterSinkConfiguration.java


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