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


Java Sink类代码示例

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


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

示例1: amqpChannelAdapter

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的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

示例2: handle

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的package包/类
@StreamListener(value = Sink.INPUT)
public void handle(Message<ProjectEvent> message) {
    ProjectEvent projectEvent = message.getPayload();
    log.info("Received new event: " + "{ projectId " + projectEvent.getProjectId() + " -> " +
            projectEvent.getType() + " }");

    if (projectEvent.getType() == ProjectEventType.CREATED_EVENT) {
        try {
            commitProcessor.importCommits(projectEvent);
        } catch (IOException e) {
            throw new RuntimeException("Could not import GitHub project", e);
        }
    }

    if (projectEvent.getType() == ProjectEventType.COMMIT_EVENT) {
        // Update query models
        LambdaResponse<Map<String, Object>> response =
                projectQueries.getTightCoupling().apply(projectEvent);
    }
}
 
开发者ID:kbastani,项目名称:service-block-samples,代码行数:21,代码来源:EventProcessor.java

示例3: shipGoodsCommandReceived

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的package包/类
@StreamListener(target = Sink.INPUT, 
    condition="payload.messageType.toString()=='ShipGoodsCommand'")
@Transactional
public void shipGoodsCommandReceived(String messageJson) throws Exception {
  Message<ShipGoodsCommandPayload> message = new ObjectMapper().readValue(messageJson, new TypeReference<Message<ShipGoodsCommandPayload>>(){});

  String shipmentId = shippingService.createShipment( //
      message.getPayload().getPickId(), //
      message.getPayload().getRecipientName(), //
      message.getPayload().getRecipientAddress(), //
      message.getPayload().getLogisticsProvider());
      
  messageSender.send( //
      new Message<GoodsShippedEventPayload>( //
          "GoodsShippedEvent", //
          message.getTraceId(), //
          new GoodsShippedEventPayload() //
            .setRefId(message.getPayload().getRefId())
            .setShipmentId(shipmentId)));
}
 
开发者ID:flowing,项目名称:flowing-retail,代码行数:21,代码来源:MessageListener.java

示例4: retrievePaymentCommandReceived

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的package包/类
@StreamListener(target = Sink.INPUT, 
    condition="payload.messageType.toString()=='RetrievePaymentCommand'")
@Transactional
public void retrievePaymentCommandReceived(String messageJson) throws JsonParseException, JsonMappingException, IOException {
  Message<RetrievePaymentCommandPayload> message = new ObjectMapper().readValue(messageJson, new TypeReference<Message<RetrievePaymentCommandPayload>>(){});
  RetrievePaymentCommandPayload retrievePaymentCommand = message.getPayload();    
  
  System.out.println("Retrieve payment: " + retrievePaymentCommand.getAmount() + " for " + retrievePaymentCommand.getRefId());
  
  camunda.getRuntimeService().createMessageCorrelation(message.getMessageType()) //
    .processInstanceBusinessKey(message.getTraceId())
    .setVariable("amount", retrievePaymentCommand.getAmount()) //
    .setVariable("remainingAmount", retrievePaymentCommand.getAmount()) //
    .setVariable("refId", retrievePaymentCommand.getRefId()) //
    .correlateWithResult();    
}
 
开发者ID:flowing,项目名称:flowing-retail,代码行数:17,代码来源:MessageListener.java

示例5: orderPlacedReceived

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的package包/类
/**
 * Handles incoming OrderPlacedEvents. 
 * 
 *  Using the conditional {@link StreamListener} from 
 * https://github.com/spring-cloud/spring-cloud-stream/blob/master/spring-cloud-stream-core-docs/src/main/asciidoc/spring-cloud-stream-overview.adoc
 * in a way close to what Axion
 *  would do (see e.g. https://dturanski.wordpress.com/2017/03/26/spring-cloud-stream-for-event-driven-architectures/)
 */
@StreamListener(target = Sink.INPUT, 
    condition="payload.messageType.toString()=='OrderPlacedEvent'")
@Transactional
public void orderPlacedReceived(String messageJson) throws JsonParseException, JsonMappingException, IOException {
  Message<Order> message = new ObjectMapper().readValue(messageJson, new TypeReference<Message<Order>>(){});
  Order order = message.getPayload();
  
  System.out.println("New order placed, start flow. " + order);
  
  // persist domain entity
  repository.persistOrder(order);    
  
  // and kick of a new flow instance
  camunda.getRuntimeService().createMessageCorrelation(message.getMessageType())
    .processInstanceBusinessKey(message.getTraceId())
    .setVariable("orderId", order.getId())
    .correlateWithResult();
}
 
开发者ID:flowing,项目名称:flowing-retail,代码行数:27,代码来源:MessageListener.java

示例6: retrievePaymentCommandReceived

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的package包/类
@StreamListener(target = Sink.INPUT, 
    condition="payload.messageType.toString()=='FetchGoodsCommand'")
@Transactional
public void retrievePaymentCommandReceived(String messageJson) throws JsonParseException, JsonMappingException, IOException {
  Message<FetchGoodsCommandPayload> message = new ObjectMapper().readValue(messageJson, new TypeReference<Message<FetchGoodsCommandPayload>>(){});
  
  FetchGoodsCommandPayload fetchGoodsCommand = message.getPayload();    
  String pickId = inventoryService.pickItems( // 
      fetchGoodsCommand.getItems(), fetchGoodsCommand.getReason(), fetchGoodsCommand.getRefId());
  
  messageSender.send( //
      new Message<GoodsFetchedEventPayload>( //
          "GoodsFetchedEvent", //
          message.getTraceId(), //
          new GoodsFetchedEventPayload() //
            .setRefId(fetchGoodsCommand.getRefId())
            .setPickId(pickId)));
}
 
开发者ID:flowing,项目名称:flowing-retail,代码行数:19,代码来源:MessageListener.java

示例7: messageReceived

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的package包/类
@StreamListener(target = Sink.INPUT)
@Transactional
public void messageReceived(String messageJson) throws Exception {
  Message<JsonNode> message = new ObjectMapper().readValue( //
      messageJson, //
      new TypeReference<Message<JsonNode>>() {});
  
  String type = "Event";
  if (message.getMessageType().endsWith("Command")) {
    type = "Command";
  }
  
  PastEvent event = new PastEvent( //
      type, //
      message.getMessageType(), //
      message.getTraceId(), //
      message.getSender(), //
      message.getPayload().toString());
  
  // save
  LogRepository.instance.addEvent(event);
  
  // and probably send to connected websocket (TODO: Not a good place for the code here!)
  simpMessageTemplate.convertAndSend("/topic/events", event);
}
 
开发者ID:flowing,项目名称:flowing-retail,代码行数:26,代码来源:MessageListener.java

示例8: setup

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的package包/类
@Before
public void setup() {
	this.testDir=System.getProperty("java.io.tmpdir") + "/hdfs-sink";
	String[] env = {"server.port:0",
			"spring.hadoop.fsUri=file:///",
			"hdfs.directory=" + this.testDir,
			"hdfs.closeTimeout=100"};
	EnvironmentTestUtils.addEnvironment(this.context, env);
	this.context.register(HdfsSinkApplication.class);
	this.context.refresh();
	this.fsShell = context.getBean(FsShell.class);
	this.sink = context.getBean(Sink.class);
	if (fsShell.test(testDir)) {
		fsShell.rmr(testDir);
	}
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:hdfs,代码行数:17,代码来源:HdfsSinkConfigurationTests.java

示例9: setup

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的package包/类
@Before
public void setup() throws IOException {
	this.testDir=System.getProperty("java.io.tmpdir") + "/dataset";
	this.nameSpace = "test";
	String[] env = {"server.port:0",
			"spring.hadoop.fsUri=file:///",
			"hdfs.dataset.directory=" + this.testDir,
			"hdfs.dataset.namespace=" + this.nameSpace,
			"hdfs.dataset.batchSize=2",
			"hdfs.dataset.idleTimeout=2000"};
	EnvironmentTestUtils.addEnvironment(this.context, env);
	this.context.register(HdfsDatasetSinkApplication.class);
	this.context.refresh();
	this.datasetName = context.getBean(DatasetOperations.class).getDatasetName(String.class);
	this.hadoopConfiguration = context.getBean(Configuration.class);
	this.sink = context.getBean(Sink.class);
	FileSystem fs = FileSystem.get(hadoopConfiguration);
	FsShell fsShell = new FsShell(hadoopConfiguration, fs);
	if (fsShell.test(testDir)) {
		fsShell.rmr(testDir);
	}
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:hdfs,代码行数:23,代码来源:DatasetSinkContextClosingTests.java

示例10: amqpChannelAdapter

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的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

示例11: websocketSink

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的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

示例12: process

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的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

示例13: ftpInboundFlow

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的package包/类
@Bean
public IntegrationFlow ftpInboundFlow(FtpSinkProperties properties, SessionFactory<FTPFile> ftpSessionFactory) {
	FtpMessageHandlerSpec handlerSpec =
		Ftp.outboundAdapter(new FtpRemoteFileTemplate(ftpSessionFactory), properties.getMode())
			.remoteDirectory(properties.getRemoteDir())
			.remoteFileSeparator(properties.getRemoteFileSeparator())
			.autoCreateDirectory(properties.isAutoCreateDir())
			.temporaryFileSuffix(properties.getTmpFileSuffix());
	if (properties.getFilenameExpression() != null) {
		handlerSpec.fileNameExpression(properties.getFilenameExpression().getExpressionString());
	}
	return IntegrationFlows.from(Sink.INPUT)
		.handle(handlerSpec,
			new Consumer<GenericEndpointSpec<FileTransferringMessageHandler<FTPFile>>>() {
				@Override
				public void accept(GenericEndpointSpec<FileTransferringMessageHandler<FTPFile>> e) {
					e.autoStartup(false);
				}
			})
		.get();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:22,代码来源:FtpSinkConfiguration.java

示例14: ftpInboundFlow

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的package包/类
@Bean
public IntegrationFlow ftpInboundFlow(SftpSinkProperties properties, SessionFactory<LsEntry> ftpSessionFactory) {
	SftpMessageHandlerSpec handlerSpec =
		Sftp.outboundAdapter(new SftpRemoteFileTemplate(ftpSessionFactory), properties.getMode())
			.remoteDirectory(properties.getRemoteDir())
			.remoteFileSeparator(properties.getRemoteFileSeparator())
			.autoCreateDirectory(properties.isAutoCreateDir())
			.temporaryFileSuffix(properties.getTmpFileSuffix());
	if (properties.getFilenameExpression() != null) {
		handlerSpec.fileNameExpression(properties.getFilenameExpression().getExpressionString());
	}
	return IntegrationFlows.from(Sink.INPUT)
		.handle(handlerSpec,
			new Consumer<GenericEndpointSpec<FileTransferringMessageHandler<LsEntry>>>() {
				@Override
				public void accept(GenericEndpointSpec<FileTransferringMessageHandler<LsEntry>> e) {
					e.autoStartup(false);
				}
			})
		.get();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:22,代码来源:SftpSinkConfiguration.java

示例15: amazonS3MessageHandler

import org.springframework.cloud.stream.messaging.Sink; //导入依赖的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


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