I have created a Spring cloud stream application that publishes messages to Solace. The publish message is triggered by an external event. I am using StreamBridge to achieve this functionality of publishing messages.
Problem: when the application starts it creates a consumer queue and a subscription to it.
Question: Since my application’s job is to only publish messages why does it create a consumer queue. Is there anything that I’ve missed setting in the properties?
My quick take on this is - the queue is created not because you have defined binding (someEvent-out-0), maybe because you have a Consumer function implemented in your application. If you comment/remove that, I believe the queue won’t be created.
Hi @giri , there isn’t any consumer function that I have defined explicitly. I’ve just autowired StreamBridge and calling the send method to publish events like the following:
I’ve tried with a simple SCS app, and like Giri said, this shouldn’t have created the queue. Especially since this is “out” binding. My code also uses streamBridge.send( the topic address , the POJO/payload ) , but I’m not sure why you’d put the binding name there.
But, we do know that Queue creation is logged in the event.log
If you have access to the logs / cli you can check the log entry when the durable queue got created, and find that client ID on either CLI or web manager - just to confirm if your app did that. And if so, we should investigate more on the complete code I think.
Is the orderPlacedEvent function a Functional Interface? For example, does it return a java.util.function.Function or java.util.function.Consumer? If so then cloud stream might be automatically picking it up and configuring it with default bindings. Note that I don’t believe this should happen if you are defining spring.cloud.function.definition and the function is not called out in that config…any chance you can share the actual code/config? Obviously feel free to take out the business logic.
Hi @marc
Here is the piece of code that is handling the external event. And on any event from an external source, it triggers streamBridge.source(binding, event)
Interesting…so it looks like the EventHandler interface has the @StreamListener annotation on it. This annotation was used in Spring Cloud Stream v2 to bind an input channel…I’m assuming that Spring Cloud Stream is picking this up and saying “hey, you want this bound to a messaging channel”. If you don’t want this function to be triggered via a message can you just remove the @EventHandler annotation?
Hi @marc , the @EventHandler annotation is not from Spring instead it is from a third-party tool that I am using. I cannot remove the annotation.
This annotation is the one that catches external events.
Interesting, can you share what the 3rd party tool is? Where is it connecting to receive the events? That would help figure out what the proper path forward would be.
Can you try the suggestions that Oleg made in that post and see if they work for you? I’m also following up with Oleg directly to see if there is a newer suggested approach since 2019.
I heard back from Oleg and it looks like they made an enhancement for this exact scenario. You can check it out in docs here, but the summary is to set spring.cloud.stream.function.autodetect property to false.
I’m wondering if it could be that you need a newer version of Spring Cloud Stream. Can you check the FunctionConfiguration class on your classpath and see if it has the logic to use autoDetect in it?
Note that I had spring-cloud.version 2020.0.2 which did NOT pick it up, but changing to 2020.0.4 it seems to be correct. 2020.0.4 brought in spring-cloud-stream-3.1.4 for me.
I am using StreamBridge .send method to bind the data but did not get any message data in below out put… @Bean public Consumer event1(StreamBridge streamBridge) { return ds
→ { DataCode dataCode = new DataCode();
dataCode.setEventType(ds.getEventType().toUpperCase());
dataCode.setNetwork(ds.getNetwork().toUpperCase());
String topic = TOPIC_PREFIX + ds.getEventType() + “/” + ds.getNetwork(); //System.out.println(“Event E1 for order creation for Network1-----------------------” +topic +ds.getEventType() +ds.getNetwork());
streamBridge.send(topic,dataCode);
}; }
output:----I am getting <message handler ID: 18bab7d0-e7d1-4859-b543-253f00bb5cf2> instead of event and network value. please suggest.{“eventType”:“update2”,
“network”: “network3”}
com/Supply/Order/update2/network3 <message handler ID: 18bab7d0-e7d1-4859-b543-253f00bb5cf2>
Yes I have but still not working always I an getting cid------>: null
public class DataCode implements Serializable {
private static final long serialVersionUID = 1L;