Try PubSub+

Spring Cloud Stream publishing messages

Mike13Mike13 Member Posts: 26

I have heard that SCS should no longer be used together with flux (flux destroys that: retry handling, error handling, transmission confirmation).
With StreamBridge messages can be published. But in my opinion the StreamBridge is not quite consistent with the other declarative and functional handling of SCS.
Are there still alternatives with which I can still work declaratively and functionally for publishing messages?

Comments

  • marcmarc Member, Administrator, Moderator, Employee Posts: 504 admin

    Hi @Mike13,

    Hope you're doing well! There is actually another option to publish messages to dynamic topics. Instead of StreamBridge you can specify a special header using BinderHeaders.TARGET_DESTINATION. This tells the binder (if the binder supports it - the Solace binder does) to override the output destination and send to this topic instead.

    You can find more info here in section 6: https://codelabs.solace.dev/codelabs/spring-cloud-stream-beyond/index.html?index=../..index#5

    Hope that helps!

  • Mike13Mike13 Member Posts: 26

    Hi @marc

    I am very well, thanks. How are you? Yes, we use this option (BinderHeaders.TARGET_DESTINATION) for several use cases (e.g. request/reply with a dynamic reply address). All the cases I know work with Function but I don't know any case for Supplier.
    In the link that you provided (thanks for that) the example is also with a function. The article says that this would work with Supplier too, but how :-)?

    Best regards
    Mike

  • marcmarc Member, Administrator, Moderator, Employee Posts: 504 admin

    Hey @Mike13,

    Hmm..I'm just passing through with a few minutes so I haven't compiled this, but something like this should work:

    @Bean
    public Supplier<Message> mySupplier() {
    return () -> {
    String payload = "whatever";
    String myTopic = useYourBusinessLogic();
    logger.info("Publishing to: " + myTopic);
    return MessageBuilder.withPayload(payload).setHeader(BinderHeaders.TARGET_DESTINATION, myTopic).build();
    };
    }

Sign In or Register to comment.