本文整理汇总了Java中org.springframework.cloud.stream.annotation.StreamListener类的典型用法代码示例。如果您正苦于以下问题:Java StreamListener类的具体用法?Java StreamListener怎么用?Java StreamListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StreamListener类属于org.springframework.cloud.stream.annotation包,在下文中一共展示了StreamListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的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);
}
}
示例2: handleEvent
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@StreamListener(DomainEventSink.CHANNEL_NAME)
<T extends DomainEvent> void handleEvent(T event) {
logger.debug("Received event '{}' for handling", event);
handlers.keySet().stream()
.filter(eventType -> eventType.isAssignableFrom(event.getClass()))
.flatMap(handledEvent -> handlers.get(handledEvent).stream())
.forEach(eventHandler -> {
try {
logger.debug("Delegating event '{}' to handler '{}'", event, eventHandler);
((DomainEventHandler<T>) eventHandler).handleEvent(event);
} catch (Exception ex) {
//Ignored to let other handlers process event
logger.error("Handler '{}' threw exception for event '{}'", eventHandler, event, ex);
}
});
}
示例3: apply
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的package包/类
@StreamListener(value = FriendSink.INPUT)
public void apply(Message<FriendEvent> friendEvent) {
log.info("Event received: " + friendEvent.toString());
switch (friendEvent.getPayload().getEventType()) {
case FRIEND_ADDED:
userRepository.addFriend(
friendEvent.getPayload().getSubject().getUserId(),
friendEvent.getPayload().getSubject().getFriendId());
break;
case FRIEND_REMOVED:
userRepository.removeFriend(
friendEvent.getPayload().getSubject().getUserId(),
friendEvent.getPayload().getSubject().getFriendId());
break;
}
}
示例4: tweet
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的package包/类
@StreamListener(value = CloudConnectorChannels.INTEGRATION_EVENT_CONSUMER, condition = "headers['connectorType']=='SendRewardToWinners'")
public synchronized void tweet(IntegrationRequestEvent event) {
Map<String, Object> results = new HashMap<>();
Collection winners = (Collection) event.getVariables().get("top");
String campaign = String.valueOf(event.getVariables().get("campaign"));
for(Object winner:winners){
logger.info(append("service-name", appName),"#"+campaign+"#################################################################");
logger.info(append("service-name", appName),"# Reward time!!! You WON "+winner+"!!! ");
logger.info(append("service-name", appName),"#################################################################################");
}
IntegrationResultEvent ire = new IntegrationResultEvent(event.getExecutionId(),
results);
integrationResultsProducer.send(MessageBuilder.withPayload(ire).build());
}
示例5: shipGoodsCommandReceived
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的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)));
}
示例6: retrievePaymentCommandReceived
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的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();
}
示例7: orderPlacedReceived
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的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();
}
示例8: retrievePaymentCommandReceived
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的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)));
}
示例9: messageReceived
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的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);
}
示例10: registerHandlerMethodOnListenedChannel
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的package包/类
protected final void registerHandlerMethodOnListenedChannel(Method method, StreamListener streamListener, Object bean) {
Assert.hasText(streamListener.value(), "The binding name cannot be null");
if (!StringUtils.hasText(streamListener.value())) {
throw new BeanInitializationException("A bound component name must be specified");
}
final String defaultOutputChannel = StreamListenerMethodUtils.getOutboundBindingTargetName(method);
if (Void.TYPE.equals(method.getReturnType())) {
Assert.isTrue(StringUtils.isEmpty(defaultOutputChannel),
"An output channel cannot be specified for a method that does not return a value");
}
else {
Assert.isTrue(!StringUtils.isEmpty(defaultOutputChannel),
"An output channel must be specified for a method that can return a value");
}
StreamListenerMethodUtils.validateStreamListenerMessageHandler(method);
mappedListenerMethods.add(streamListener.value(),
new StreamListenerHandlerMethodMapping(bean, method, streamListener.condition(), defaultOutputChannel,
streamListener.copyHeaders()));
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:20,代码来源:StreamListenerAnnotationBeanPostProcessor.java
示例11: doPostProcess
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的package包/类
private void doPostProcess(StreamListener streamListener, Method method, Object bean) {
streamListener = postProcessAnnotation(streamListener, method);
String methodAnnotatedInboundName = streamListener.value();
String methodAnnotatedOutboundName = StreamListenerMethodUtils.getOutboundBindingTargetName(method);
int inputAnnotationCount = StreamListenerMethodUtils.inputAnnotationCount(method);
int outputAnnotationCount = StreamListenerMethodUtils.outputAnnotationCount(method);
boolean isDeclarative = checkDeclarativeMethod(method, methodAnnotatedInboundName, methodAnnotatedOutboundName);
StreamListenerMethodUtils.validateStreamListenerMethod(method,
inputAnnotationCount, outputAnnotationCount,
methodAnnotatedInboundName, methodAnnotatedOutboundName,
isDeclarative, streamListener.condition());
if (isDeclarative) {
invokeSetupMethodOnListenedChannel(method, bean, methodAnnotatedInboundName, methodAnnotatedOutboundName);
}
else {
registerHandlerMethodOnListenedChannel(method, streamListener, bean);
}
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:21,代码来源:StreamListenerAnnotationBeanPostProcessor.java
示例12: receive
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的package包/类
@StreamListener
public void receive(@Input(Processor.INPUT) SubscribableChannel input,
@Output(Processor.OUTPUT) final MessageChannel output1,
@Output(StreamListenerTestUtils.FooOutboundChannel1.OUTPUT) final MessageChannel output2) {
input.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
if (message.getHeaders().get("output").equals("output1")) {
output1.send(org.springframework.messaging.support.MessageBuilder
.withPayload(message.getPayload().toString().toUpperCase()).build());
}
else if (message.getHeaders().get("output").equals("output2")) {
output2.send(org.springframework.messaging.support.MessageBuilder
.withPayload(message.getPayload().toString().toLowerCase()).build());
}
}
});
}
示例13: save
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的package包/类
@StreamListener
@Output(CustomProcessor.OUTPUT)
public Flux<Void> save(@Input(CustomProcessor.INPUT)
Flux<Comment> newComments) {
return repository
.saveAll(newComments)
.flatMap(comment -> {
meterRegistry
.counter("comments.consumed", "imageId", comment.getImageId())
.increment();
return Mono.empty();
});
}
示例14: save
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的package包/类
@StreamListener
@Output(Processor.OUTPUT)
public Flux<Comment> save(@Input(Processor.INPUT) Flux<Comment> newComment) {
return repository
.saveAll(newComment)
.map(comment -> {
meterRegistry
.counter("comments.consumed", "imageId", comment.getImageId())
.increment();
return comment;
});
}
示例15: broadcast
import org.springframework.cloud.stream.annotation.StreamListener; //导入依赖的package包/类
@StreamListener(ChatServiceStreams.NEW_COMMENTS)
public void broadcast(Comment comment) {
if (webSocketCommentSink != null) {
log.info("Publishing " + comment.toString() +
" to websocket...");
webSocketCommentSink.next(comment);
}
}