Spring Integration Asynchronous error handling - spring

In Spring integration, I have the to deal with dynamic channels creation but when I debug the application I am seeing a “blocking” problem between different channels.
In order to obtain the dynamic channels, I divided the application in parent/children contexts and I have the following Spring integration infrastructure:
Gateway (parent) --> Transformer(Parent) --> Router (Parent/Child) --> TCP outbound (child)
This configuration works fine when all the TCP connections are OK. For testing purposes, I am stopping the different servers where the clients are connected and I could see how the errorChannel only receives errors (connection refused) but the rest of the adapters are also stopped. I would like to redirect/discard/separate these error and avoid the propagation to the common errorChannel.
I understand the errorChannel is a common channel, shared in the parent context but how can I develop a complete separated scenario for each child context?. Is the common Gateway the problem?
I see the post Error handling in Spring integration flow async but I have a complete separated environment for each child and I would like to take the advantage of these dynamic separation. Is this possible?

You can add another gateway in each child with its own error channel.
--> Router (Parent/Child) -> service-activator (child) -> gateway(child) -> TCP Out.
The gateway service interface needs a void return because no reply is expected.

Related

Spring Integration reply to Publisher

I have 2 flows implemented in Spring Integration using DSL:
REST -> AMQP -> Consumer -> Service
AMQP -> Consumer -> Service
The first flow is just a HTTP Message Publisher for clients who cannot publish directly to AMQP.
How can I let the Publisher know when the message processing failed in Service?
I was looking at Publisher Confirms and Service Acks pattern with DirectChannel, so that the Publisher can synchronously receive the error message, if I understand this correctly. However
this will block the Publisher until Service returns (or throws Exception).
What are the options in Spring Integration (since it is EIP based) to handle such situation where the Publisher should be informed of message processing failures without being blocked? This is also more of a design question.
REST -> AMQPoutboundGateway -> AmqpInboundGateway -> Service
By using gateways, the outbound gateway will block awaiting a 'success' reply from the service.
Add an error channel to the inbound gateway; if the service fails, the error flow will be invoked, and you can configure that flow to return the failure to the calling gateway.
You can use an async outbound gateway if you don't want to block, but then you'll need some other mechanism to return the result to the caller.

What is the major difference between Mule ESB VM and JMS component

I want to know the major difference between VM and JMS component of Mule ESB. Can someone help me to know it.
As per Mule documentation, VM transport is for intra-JVM communication between Mule flows. So, that means when you use a VM in your flow, you can communicate between different flows in the application.
A flow containing VM inbound cannot be called externally from external application as thus the flow is equivalent to a private flow used within the application. By default uses in-memory queues.
Please go through the documentation :- https://docs.mulesoft.com/mule-user-guide/v/3.8/vm-transport-reference
On the other hand as per Mule documentation, JMS is an external host, allows communication between different components of a distributed application and JMS transport lets you easily send and receive messages to queues and topics for any message service which implements the JMS specification.
A flow, which has JMS inbound can be called from externally unlike VM. Documentation is here :- https://docs.mulesoft.com/mule-user-guide/v/3.8/jms-transport-reference
Within the application, if you send the control from one flow to another flow we use VM.VM can be used as both inbound and outbound.
Outside the application, for example, A application want to send something to B application(external application) there we use JMS.

service activator acting as outbound gateway for invoking bean method

I am new to spring integration and was going through the definition of service activator. The definition says that it is used to call a method and wrap the result in the response message. The definition also tells that it is a outbound gateway for invoking the bean method. I am not clear on the second statement. As I understand outbound gateway is to send the request from the application to external application and get the response back into the application. So, if a bean is invoked, it is invoked within the application and hence it should be inbound gateway right. Please let me know where I am wrong.
There are two types of integration - with external systems using various protocols, and with legacy java code using method invocation.
Within that, there are one-way integrations (provided by channel adapters) and two-way integration (request/response, provided by gateways). In each case, the integration can be inbound to the message flow, or outbound from it.
The <int: .../> namespace provides inbound and outbound channel adapters for invoking legacy code from the messaging flow, in the latter case (outbound) the method return type must be null. You could also invoke the same method with a service activator, but the channel adapter is preferred because it's clear it's a one-way integration.
On the inbound side, the messaging gateway (<int:gateway/>) is provided to allow legacy java code interact with the messaging flow ("call" it) without any specific dependencies.
There is no <int:outbound-gateway/> for invoking a method because the service activator provides that functionality.
If you can point us to the documentation that caused the confusion, we can try to improve it; please open a documentation JIRA issue.

Use SimpMessagingTemplate without creating a web socket message broker Spring 4

Can I send a message to a message broker using SimpMessagingTemplate#convertAndSendToUser or SimpMessagingTemplate#convertAndSend methods without settings up a websocket message broker using #EnableWebSocketMessageBroker?
What I'm trying to do is utilise one websocket server to provide messaging for two application server instances(One spring 4 and one Spring 3). I created a one web server with Spring 4, Spring boot plus websocket message broker enabled.
Now I want two application servers to push messages to rabbitmq so it will broadcast them to clients subscribed to it.
First issue I faced is if there is no websockt message broker configuration available, SimpMessagingTemplate will not get autowired to application context. I couldn't get it injected without creating a websocket message board either.
Please help me to find out whether this is possible.
BTW I have a previous question unanswered related to this.
Well, After reading lots of documentation I found the answer myself. The key thing is this architecture is following.
In this architecture spring act as a gateway for communication between the message broker and client. Spring doesn't do anything(Other than when it necessary) but forward the request to the message broker(STOMP messages). The configuration kept on Spring defines couple of important things. One is the exchange and other were routing keys. Spring configuration gives us an abstract layer so we subscribe and push messages to message broker without a fuss.
SimpMessagingTemplate is the abstract layer which we use to communicate with message broker. Spring creates the bean using the given details. Well I couldn't create a instance of SimpMessagingTemplate manually. I have to update Spring 3 application to Spring 4 in order to use websockets.
Since Spring and message broker is decoupled, clustering the application instance doesn't make any effect on message broker. Spring will communicate to message broker only when it need to subscribe to a channel or when it need to publish a message to a channel. So if there is two instances subscribing to same channel it would be two queues binding the one exchange using same routing key. Messages published into a channel will be available to all subscribers(queues) because they all use same routing key. Refer to rabbitmq stop plugin documentation for more elaborative description.

Spring Integration handle http outbound gateway failures

There are multiple servers that are listening to activemq. The chain is configured to make the http [outbound gateway] call. Suppose one of the server picks up the message and in-between if the http call fails for some reason. The message should be put back to the queue, so that another server can pick up the message and process. Can this be achieved using Spring Integration. I read lot on Transaction, however unable to find workable way.
Yes, simply set acknowledge="transacted" on the <int-jms:message-driven-channel-adapter/> and, as long as you use only direct channels (no <queue/> on the channel or task-executor on the channel's dispatcher) then any failure will cause the message to roll back.

Resources