question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple consumers of a single channel behaves inconsistently

See original GitHub issue

If two @StreamListener methods subscribe to the same input channel (with no consumer group declared), both methods receive every message behaving as one would expect in a publish-subscribe context. They seem to be assigned their own unique (anonymous) consumer group.

If I subscribe to this channel with both a @StreamListener and an aggregator created via Spring Integration’s @Aggregator annotation, it appears as if the two ended up in the same consumer group, the aggregator receiving half of the messages, the stream listener receiving the other half.

Spring Cloud Version is Dalston.SR1

channel definitions:

public interface Channels {
    String TOKEN_WRITE = "tokenWrite";
    String TOKEN_READ = "tokenRead";
    //...
    @Input(TOKEN_READ)
    SubscribableChannel tokenRead();
    @Output(TOKEN_WRITE)
    MessageChannel tokenWrite();
    //...
}

application.properties

spring.cloud.stream.bindings.tokenWrite.destination=token.t
spring.cloud.stream.bindings.tokenWrite.content-type=application/json
spring.cloud.stream.bindings.tokenRead.destination=token.t
spring.cloud.stream.bindings.tokenRead.content-type=application/x-java-object;type=api.Token

the one with the stream listener

@EnableBinding(Channels.class)
public class ChannelLogger {
    private static final Logger LOGGER = LoggerFactory.getLogger(ChannelLogger.class);

    @StreamListener(Channels.TOKEN_READ)
    public void logTokens(Message<Token> message) {
        LOGGER.info("<<token.t>>: {}", message.getPayload());
    }
}

aggregator

@EnableBinding(Channels.class)
public class TokenAggregator {
    @Aggregator(
            inputChannel = TOKEN_READ,
            outputChannel = AGGREGATED_WRITE,
            discardChannel = DISCARD_WRITE
    )
    public Message<AggregatedTokens> aggregate(List<Message<Token>> messages, @Headers Map<String, Object> headers) {
        Message<AggregatedTokens> aggregate = MessageBuilder
                .withPayload(new AggregatedTokens()
                        .withTokens(messages.stream()
                        .map(Message::getPayload)
                        .collect(Collectors.toList())))
                .copyHeaders(headers)
                .build();
    }
    //...
}

I would expect the two cases to behave identically.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
viniciusccarvalhocommented, Aug 17, 2017

Docs have been updated via 3ca2138a32937d02d622440332110eb02d8d4490

1reaction
mbogoevicicommented, Jul 7, 2017

@kicsikrumpli Here’s a complete working example: https://github.com/mbg-scratchpad/scst-gh-1007

A couple of notes: I bumped the Spring Cloud version to Edgeware Snapshot so we can get the fix for https://github.com/spring-cloud/spring-cloud-stream/issues/993 (it affects how messages are created by the aggregator are sent to the binding). In theory we should be able to backport the fix to the version of Spring Cloud Stream that comes with Dalston (i.e. Chelsea cc/@garyrussell).

It’s not entirely clear for me why the application reads and writes data to the same destination so I left that out.

This can be tested easily by sending a message like:

{"data":"ABDE","groupId":98}

to the tokenRead exchange and observing the results in a queue bound to the tokenWrite exchange and the log.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple consumers without losing messages - Stack Overflow
A single Channel<T> cannot broadcast messages to multiple consumers. Every time a message is read from the channel, the message is consumed, ...
Read more >
Rationalizing Inconsistent Consumer Behavior ... - Frontiers
If people behave inconsistently with regard to their PEBs, this may therefore be caused either by negative spillover or because behaviors are ...
Read more >
Stop alienating customers with inconsistent e-commerce CX I ...
Issues in this multi-channel customer experience (CX) can and do arise as the service relays with third parties occur.
Read more >
Interservice communication in microservices - Microsoft Learn
A single transaction may span multiple services. That can make it hard to monitor the overall performance and health of the system. Even...
Read more >
Consumers | Eventide
A consumer continuously reads messages from a single category and dispatches the messages to the handlers that have been added to the consumer....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found