What happens to messages with no matching Listener in Spring-Kafka? - spring-kafka

My understanding of the #KafkaListener is that messages are consumed by matching the listener method's argument type with the message type.
What happens to messages that do not have a matching listener?

It's not clear what you mean. What leads you to believe that?
#KafkaListener on a Method means there is a consumer (listener container) for each method so all methods get all records (unless they are in the same consumer group or you assign partitions manually).
#KafkaListener on a Class means you have to annotate multiple methods with #KafkaHandler and the framework will find which handler method to invoke based on the deserialized payload; the value deserializer must be able to deserialize the expected multiple types.
You can designate exactly one #KafkaHandler as the default handler (which is invoked if there is no match) - usually with an Object parameter.
If there is no match and no default handler method, the record goes to the configured ErrorHandler.
The default error handler logs the failure, but you can add your own to do whatever you want.

Related

Does ChannelReader<T>.ReadAllAsync return a static or dynamic enumeration?

The documentation for this method simply says:
Creates an IAsyncEnumerable that enables reading all of the data
from the channel.
Does the enumerable returned represent a snapshot of the Channel at the time of calling, or is it a 'live' view of the Channel that will behave correctly if items are added/removed by other actors while I am enumerating it?
According to the source code it enumerates the live channel, not a snapshot.
Of course, inherited classes that override this behavior. You need to examine your specific instance.

Method annotated with #KafkaListener not called if there are no messages

I am using spring-kafka and the method annotated with #KafkaListener is not called if the consumer.poll() method does not return any message. Is it possible to enforce the calling of a method even if consumer.poll() returns an empty list of messages using #KafkaListener?
No, but you can set the idleEventInterval on the listener container factory and then consume ListenerContainerIdleEvents; the event is emitted if a poll returns no records have been received during that interval.
Consume the events by implementing ApplicationListener<ListenerContainerIdleEvent> or using an #EventListener method that receives a ListenerContainerIdleEvent.

EJB StatelessBean business method with Object as parameter is becoming null after deseriazation

Am using EJB Sateless Bean.
in my Bean i have one method which takes 2 parameters, first parameter is Date and the second parameter is an Object, whose syntax is as below.
RemoteINterface rm=homeInterface.create();
rm.method1(date1,mycustomObject);
AT client side am creating myCustomObject and assigned values to its properties .But when the request reaches Server side ,this object is coming as null after deserization.
Here my custom object is implementing serizable interface and it has equals and hashcode method with public default contrutor.But still am getting null.
Any idea what am missing here?

Workflow: Trying to pass an object variable to a class method

I am having a tough time trying to pass a parameter into my method when I go to invoke it.
I new up a variable called setupNewCase, then I populate it with data. Once I do that, I then try to invoke the method. It normally works when I don't have a value to pass into it, but it doesn't work here in this case as I am trying to pass something into it.
To pass parameters to the invoked method you use the Parameters property on the InvokeMethod activity. Its available on the activity's properties grid and not directly on the designer.
You would use TargetObject when invoking a method on an instance object but since your CommonMethods class is static you won't ever instantiate it and therefore TargetObject should be empty.

Modifying a Biztalk message from custom code

Disclaimer: I am a complete biztalk newbie.
I need to be able to read and potentially edit 4 nodes in a biztalk message; preferably this needs to be done from a c# helper class as I am making a service call and also have unit tests written for this.
I already have this class wired up and it works with the XLANGMessage class, the problem I am running into is at this point in the orchestration the message is a Schema based type and doesn't seem to have any way for me to modify it.
I've done some reading and found a few ideas but have not been able to confirm if any of these can work from custom code.
1 write a map to transform the incoming message to the desired type
or
2 write something like this in your helper component to transform the message
public XmlDocument TransformMessage(XLANGMessage message)
Then pass the result document to a biztalk message in a message assignment shape.
responseMessage = xmlDocument;
You may get better performance if you pass streams instead of messages around.
You can pass messages into and out of C# helper classes easily. The simplest way is just to treat input parameters and return values as of type System.Xml.XmlDocument. The XLANG/s engine will safely cast back and forth from the XLANGMessage type to XmlDocument.
As you are essentially creating a "new" instance of the message (messages are immutable in BizTalk), the call to your helper class needs to be performed in a Message Assignment shape, with the outer Construct shape constructing the copy of your original message.
public static XmlDocument UpdateMyMessage(XmlDocument sourceMessage)
{
/* Do stuff to your Message here */
return sourceMessage;
}
A best-practice to consider is to declare all your C# helper methods as Static. This will avoid any issues with de/serialisation of your helper class during dehydration.
Are BizTalk messages immutable?
Generally speaking they are however, by creating a “corrective” orchestration and using a pass by reference option on the incoming message parameter, an existing message can be modified.

Resources