/** * Registers a MessageConsumer at the receiver endpoint. * * {@link MessageConsumer consumers} have to be thread safe as they might be called from multiple threads * in parallel (e.g. for kinesis streams there is one thread per shard). * * @param messageConsumer registered EventConsumer */ @Override public final void register(MessageConsumer<?> messageConsumer) { messageDispatcher.add(messageConsumer); }
public AbstractMessageReceiverEndpoint(final @Nonnull String channelName, final @Nonnull MessageInterceptorRegistry interceptorRegistry, final @Nullable ApplicationEventPublisher eventPublisher) { super(channelName, interceptorRegistry); messageDispatcher = new MessageDispatcher(); this.eventPublisher = eventPublisher; }
private MethodInvokingMessageConsumer<?> eventConsumerFor(final EventSourceConsumer annotation, final Method annotatedMethod, final Object bean) { return new MethodInvokingMessageConsumer<>(annotation.keyPattern(), annotation.payloadType(), bean, annotatedMethod); }
private CompletableFuture<ChannelPosition> consumeMessageStore() { final ThreadFactory threadFactory = new CustomizableThreadFactory("synapse-eventsource-"); return CompletableFuture.supplyAsync(() -> { messageStore.stream().forEach(message -> { final Message<String> interceptedMessage = getMessageLogReceiverEndpoint().getInterceptorChain().intercept(message); if (interceptedMessage != null) { getMessageLogReceiverEndpoint().getMessageDispatcher().accept(interceptedMessage); } }); return messageStore.getLatestChannelPosition(); }, newSingleThreadExecutor(threadFactory)); }
messageConsumers .stream() .filter(consumer -> matchesKeyPattern(message, consumer.keyPattern())) .forEach((MessageConsumer consumer) -> { try { final Class<?> payloadType = consumer.payloadType(); if (payloadType.equals(String.class)) { consumer.accept(message); } else { Object payload = null; consumer.accept(tMessage);
final Message<String> interceptedMessage = intercept(receivedMessage); if (interceptedMessage != null) { getMessageDispatcher().accept(interceptedMessage);
private MethodInvokingMessageConsumer<?> messageQueueConsumerFor(final MessageQueueConsumer annotation, final Method annotatedMethod, final Object bean) { return new MethodInvokingMessageConsumer<>(annotation.keyPattern(), annotation.payloadType(), bean, annotatedMethod); }
getMessageDispatcher().accept(interceptedMessage);
@Override public void accept(final ShardResponse response) { final InterceptorChain interceptorChain = interceptorRegistry.getInterceptorChain(channelName, RECEIVER); response.getMessages().forEach(message -> { try { final Message<String> interceptedMessage = interceptorChain.intercept(message); if (interceptedMessage != null) { messageDispatcher.accept(interceptedMessage); } } catch (final Exception e) { LOG.error("Error processing message: " + e.getMessage(), e); } }); channelDurationBehind.updateAndGet(behind -> copyOf(behind) .with(response.getShardName(), response.getDurationBehind()) .build()); if (eventPublisher != null) { eventPublisher.publishEvent(builder() .withChannelName(channelName) .withChannelDurationBehind(channelDurationBehind.get()) .withStatus(RUNNING) .withMessage("Reading from kinesis shard.") .build()); } }