# Spring Cloud Stream publishing messages

**URL:** <https://community.solace.com/t/spring-cloud-stream-publishing-messages/911>\
**Category:** General Discussions\
**Tags:** spring-cloud-stream\
**Created:** [August 31, 2021, 7:52am UTC](https://community.solace.com/t/spring-cloud-stream-publishing-messages/911 "2021-08-31T07:52:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike13](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@Mike13](https://community.solace.com/u/Mike13)\
**Post date:** [August 31, 2021, 7:52am UTC](https://community.solace.com/t/spring-cloud-stream-publishing-messages/911/1 "2021-08-31T07:52:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![marc](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/marc/32/2191_2.png) [@marc](https://community.solace.com/u/marc)\
**Post date:** [September 2, 2021, 5:37pm UTC](https://community.solace.com/t/spring-cloud-stream-publishing-messages/911/2 "2021-09-02T17:37:09Z")

</div>

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: [Spring Cloud Stream - Beyond the Basics](https://codelabs.solace.dev/codelabs/spring-cloud-stream-beyond/index.html?index=..%2F..index#5)

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Mike13](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@Mike13](https://community.solace.com/u/Mike13)\
**Post date:** [September 3, 2021, 1:24pm UTC](https://community.solace.com/t/spring-cloud-stream-publishing-messages/911/3 "2021-09-03T13:24:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marc](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/marc/32/2191_2.png) [@marc](https://community.solace.com/u/marc)\
**Post date:** [September 7, 2021, 8:53pm UTC](https://community.solace.com/t/spring-cloud-stream-publishing-messages/911/4 "2021-09-07T20:53:17Z")

</div>

Hey @Mike13,

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

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

```

---

<div class="post-metadata">

**Author:** ![Mike13](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@Mike13](https://community.solace.com/u/Mike13)\
**Post date:** [September 16, 2021, 12:05pm UTC](https://community.solace.com/t/spring-cloud-stream-publishing-messages/911/5 "2021-09-16T12:05:14Z")

</div>

Hey @marc

Thanks for the food for thought :-)! I managed to reach my goal:

```auto
    @Bean
    public MyObjectPublisher myObject() {
        return new MyObjectPublisher();
    }

    public class MyObjectPublisher implements Supplier<MyObject> {

        private BlockingDeque<MyObject> myObjects = new LinkedBlockingDeque<>();

        @Override
        public MyObject get() {
            return myObjects.poll();
        }

        public void publish(MyObject personWithHeight) {
            myObjects.add(personWithHeight);
        }
    }

   
   spring.cloud.function.definition= myObject
   spring.cloud.stream.bindings.myObject-out-0.destination = xy

```

For publishing I inject the MyObjectPublisher into mycode and call publish…  
The problem with the approach: It seems to take forever until a message is published.

---

<div class="post-metadata">

**Author:** ![marc](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/marc/32/2191_2.png) [@marc](https://community.solace.com/u/marc)\
**Post date:** [September 17, 2021, 5:28pm UTC](https://community.solace.com/t/spring-cloud-stream-publishing-messages/911/6 "2021-09-17T17:28:59Z")

</div>

Hey @Mike13,

Glad you got it working but this does seem a bit harder to follow than StreamBridge would be IMO. And also not ideal that it takes a while until the message is published. Can you maybe elaborate some more on “not quite consistent with the other declarative and functional handling” ?

---

<div class="post-metadata">

**Author:** ![Mike13](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@Mike13](https://community.solace.com/u/Mike13)\
**Post date:** [September 24, 2021, 11:20am UTC](https://community.solace.com/t/spring-cloud-stream-publishing-messages/911/7 "2021-09-24T11:20:11Z")

</div>

Hey @marc  
I try to elaborate it, yes :-)…  
When you have a consumer or a function:

- It is functional
- You create a bean, so in the code you don’t see anything like “myObject-in-0.destination”, you don’t even “know” that this bean is a Consumer from a Messaging system
- Everything that smells like messaging is done via the configuration

I hope I could explain it with this in a way that is somewhat understandable.  
It doesn’t bother me much, but it doesn’t feel consistent to me.

---

<div class="post-metadata">

**Author:** ![arpit\_k](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@arpit\_k](https://community.solace.com/u/arpit_k)\
**Post date:** [October 14, 2021, 5:05am UTC](https://community.solace.com/t/spring-cloud-stream-publishing-messages/911/8 "2021-10-14T05:05:13Z")

</div>

Hi Team,

\*\*Need some input on spring cloud streaming with solace for which we are streaming a queues and want to have a batch operation to control the no of messages ,batch size and sequence of events what will be the configuration if wee need to progress as i can see for kakfa itis max.poll.records, will below configuration as ok or do we need some else

queueMaxMsgSize  
Maximum message size for the consumer group queue.

queueQuota  
Message spool quota for the consumer group queue.

in short want to consume the data in batch ,so if there increase in no if events messages in some time we can limit to say 100 messages in fixed delay of 1000 ms.

Thanks in advance  
Arpit
