Using ReplyingKafkaTemplate across two different applications - spring-kafka

I have a spring boot application1 that send a message to request topic. On receiving this message a different spring boot application2 consumes message does processing and sending response in response topic. Can I use replying-template in application1 for this integration. In application2 do I need make changes so that correlational is sent back while sending response in application2?

If application2 uses a #KafkaListener with a non-void return type, the listener adapter will take care of the correlation id.
If it's a void #KafkaListener and you are sending the reply with a KafkaTemplate (or some other means) then, yes, you need to propagate the correlation id header from the inbound message into the reply.

Related

Automatically adding custom header to message based on request scope

RequestClients in my ApiGateway are injected (using default MS DI) in HTTP request handlers (in those handlers I have access to current request scope). What I want is to automatically, for each RequestClient, to add custom message header where I could put some data from request scope. Use case is to take JWT from request and add it to message as custom header. Then on consumer side I need, for each received request, check that custom header, verify JWT, and add some data from it to consumed request scope so I could access for example IUserContext or something like that. I want to avoid manually adding jwt to message contract for example.
How I can configure MassTransit on Client and Consumer side to achieve what I want? I already read docs about middleware and pipes and observers but still I can't figure it out...
Using RabbitMQ transport.
So, this is pretty complicated to put into a post, so I created a complete sample that shows how to use MassTransit Scoped Filters.
In this sample, an action filter is registered with the controllers to automatically extract the Token header and store it so that it can be used when publishing or sending messages from a controller. The MassTransit filters are configured on the bus, so they're available to all receive endpoints.

Asynchronous JMS

I'm trying to understand OSB and i have the situation shown in figure.
JMSProducer is a Business Service that produce a message (request) that is put in RequestQueue
JMSConsumer is a proxy consume the message request
JMSReplyProducer is a Business Service JMSReplyProducer generate a response
JMSReplyConsumer is a proxy that consume the response.
I have problem to set the flow. I'm using OEPE to setup the Oracle Service BUS. I've already create a JMSProducer that send a request to JMSconsume and I let
JMSConsumer to consume the request. In JMSConsumer i have a pipeline pair and in the request pipeline a node stage with a log.
I don't understand, as shown in Figure, how to put in comunication the JMSConsumer with JMSReplyProducer and let JMSReplyCOnsume to consume the response.
Set up the queues first
The OSB cluster on the left has a proxy service (represented by the circle at the top left)
That proxy routes to a JMS-transport business service with URL pointing to RequestQueue, and Is Response Required checked, and using the default correlation ID to pull from ResponseQueue
On the cluster on the right, create a JMS-transport proxy that reads from RequestQueue, has Is Response Required checked, and outputs back to ResponseQueue. You can then fill out that proxy to do whatever you want.

Timeout in two-way receive port when redirecting failed messages

I've a two-way WCF receive port, where i've checked both:
1) Route failed messages
2) Suspend request message on failure
This configuration is needed to redirect failed messages to our "exception portal".
When a message is received and it fails validation in XMLReceive pipeline, the message is redirected to our "exception portal" as expected.
The problem is however that the consumer of the WCF service never get's a fault, so the Connection gets a timeout after a while, which is very confusing for the consumer.
Is there anyway to fix this problem? Am I missing something?
What's happening currently is that the message fails on the Receive pipeline, gets routed to your portal, but no response gets routed back. You have to make sure to send a message back. You could do that by:
creating an Orchestration that does the validation (instead of doing it on the pipeline), and making sure to send a response int he orchestration as well as routing failures to your portal
creating a custom component that validates the message (perhaps by calling the XML Validation pipeline in a try block and catching the exception without rethrowing it); on error it sends the message to your portal, and replaces pInMsg with something sensible to send back to the partner.
having your portal receive location be a request response port (perhaps, again, with an orchestration behind it), and route the response back to the WCF two way port. This way is more involved, and to be honest I'm not entirely sure what a working implementation would look like here, but it may be possible.
If it were up to me, I'd go for the Orchestration. You can certainly call the XML Validator pipeline from an orchestration, or you could use other validation logic in there (for example calling BRE).

BizTalk sending custom WCF headers with message level security

I'm attempting to have BizTalk broker the communication to a WCF service that maps some of its data within the response message's header and not the body portion. After researching, the solution was to write the header data to the OutboundCustomHeaders message context property and then the BizTalk WCF adapter will inject it into the outgoing message. This worked perfectly until I enabled message level security using a certificate. In this case, the header still gets included within the response message but AFTER the message is encrypted. This causes the receiving client to throw a MessageSecurityException with the message 'required message part was not encrypted."
Is there a way to configure BizTalk to write the OutboundCustomHeaders before encryption occurs or another way to inject my header in the response?
I'm not sure how much it helps or complicates the answer, but the receive location in BizTalk is using the ws2007HttpRelayBinding to create an Azure endpoint for the client connections.
The solution for this problem was found by creating a custom behavior that adds the required header to the channel protection requirements and attaching it to the ws2007HttpRelayBinding.
I used the following link as a reference to my solution: WCF custom messages security

Netty http pipelining approach validation

I have implemented a channel handler for handling http pipelining. My code is at github: https://github.com/huntc/netty-http-pipelining
My question is around the approach that I have taken and whether it is a reasonable one in the context of Netty's architecture.
When my HttpPipeliningHandler receives an upstream HttpRequest it then forms a new message event of type OrderedUpstreamMessageEvent. This event is also part of my package and retains information in relation to the request that will be required when formulating reply messages.
When a channel handler further upstream receives the OrderedUpstreamMessageEvent it forms a reply by generating a OrderedDownstreamMessageEvent e.g.:
ctx.sendDownstream(new OrderedDownstreamMessageEvent(oue, somemessage));
where
ctx = ChannelHandlerContext instance
oue = OrderedUpstreamMessageEvent instance
somemessage = some message instance to be sent as an http response
You can also do more fun stuff like send chunked replies.
Does this approach look reasonable? It certainly works! Is it regular/acceptable to transform message events in an upstream handler? Obviously if the message event is transformed again then the pipelining functionality will not work.
I had a quick look... A few comments.
1) Your access of PriorityQueue must be synchronized as the downstream event may be fired by any thread.
2) Same needs to be done for nextRequiredSequence or use AtomicInteger which should be better
3) You want to use Channel.close()
The rest looks good

Resources