Spring AMQP custom message correlation using an identifier generated by the app - spring-amqp

Spring AMQP custom message correlation using an identifier generated by the app for the outbound gateway using spring integration.
We have a requirement where we need to correlate messages for outbound gateway with an id generated by app, in which actual processing of the messages would happen in external system and the response for the request will come as post from the external system, so we cannot rely on amqp_correlation data.
If you provide the steps for this that will be great.
Solution Tried
Set the correlation key in the rabbit template
Create Message of type AMQP, set the header name with the correleation key set in the template with some generated value
Provide header-mapper in the AMQP outbound gateway for the custom header name
Result
Rabbit template was able to map with the custom header, However it generates its own value, Not using the value that was set in the request/reply messages

Please open a new feature JIRA Issue for this.
Bear in mind it will be your responsibility to ensure the correlationId is unique.
You might be able to work around it by subclassing the template and overriding sendToRabbit; and set up the correlationId there; you would have to save off the template's correlationId (ideally in the message in a different header, but perhaps in a Map) and have the server return that header too.
protected void sendToRabbit(Channel channel, String exchange, String routingKey, boolean mandatory,
Message message) throws IOException {
// fix up properties
super.doSend(...);
}
You would also have to override onMessage() to restore the proper correlationId for the inbound request.

Related

SERILOG: Difference between ForContext and and

I am using the static Logger with the following setup:
Log.Logger = new LoggerConfiguration()
.WriteTo.Seq("http://localhost:5341)
.CreateLogger();
with the following in all my micro-services:
_log = Log.ForContext<GameBase>()
.ForContext("CustomerID", CustomerID);
This code inserts an CustomerID property in each event but not to the message body.
Question: Is there a way to enrich all logs for this context so that the MESSAGE BODY contains this information as well? Like an enricher that would prepend a string to each message body? There are some items I really want to see in the events without having to drill down on each event.
Also, I'm not finding much documentation on the Enrichers. Is there one to not display the full context path?
The message body is configured at the Sink level, usually by defining an outputTemplate (if the Sink supports it, not all of them do). By using the ForContext you are making the CustomerID property available to all messages written to this log instance, but it's on the Sink configuration that you define how this property will be used / shown.
You can see examples in Serilog's documentation under Formatting Output

Filtering is not working on C API

Solace filtering is not working , able to publish but not able to consume. the selector just ignore my messages while posting. please give me the solution for that.
When a Solace selector is used, a consuming client only receives a message if the selector evaluates to true when the message’s header field and property values are substituted for their corresponding identifiers in the selector. The Solace message broker filters out messages that do not match.
Solace selectors can only be set for consumers or browsers that are bound to a queue or a durable topic endpoint.
To publish a message that will match a selector, the selector string must be contained in the user property map, or in a specific message header field. The Destination property on a message defines where the message is published to. This will be either a topic or a queue. It cannot be used to match a selector.
For a list of message headers that can be used to match a selector, and its corresponding selector identifier string, please see the Solace Messaging API documentation page here: https://docs.solace.com/Solace-PubSub-Messaging-APIs/Developer-Guide/Using-Selectors.htm
If your consumer is not receiving the message while using a selector, please ensure that the selector string matches what is contained in the header property or user property map of the message.

Sending message with CAPL and dbc signal values

I am using CAPL to simulate a test envirmonet for some small tests and i am having problems sending messages or more specific setting up the values.
I am able to read Signal Values with $SignalName, also i am able to set signal values like that.
If i am using this code to send a message the message data is always 0:
on key 't'
{
message MessageName msg;
setSignal(SignalName,i);
write("Value: %d",i);
outport(msg);
}
Witch makes kinda sence becouse i think the message objects are intended to be used to send bytes witch you can access through msg.byte()
I know that i can set signals in messages by msg.SignalName, but again this seems not the right way. I think there should be a way to send a message and all the signals contained in the message are set to the values set by SetSignal() function. Otherwise the SetSignal Funktion is a bit useless
Maybe somebody has an idea.
Thank you
I am using CANalyzer version 8.2 and I do not have the option to use SetSignal(signal, value) function. Setting the signal values by accessing the message selectors seems to be a reasonable approach. However you used the function outport! You need to use the output function to transmit messages.
on key 't' {
message MessageName msg;
msg.signal1 = value1;
output(msg);
}
For this method the database has to be configured so that the message msg contains all the necessary signals (signal1).
If you want to set all signal values to the start values configured in the database use the function:
setSignalStartValues(message msg);
You can set up an interaction layer that will handle the messages as defined in the CAN database (DBC file) assigned to the node. The interaction layer will need some attributes in the database to define how the messages have to be sent. If not already present you may have to add these attributes. If the Tx messages are not sent as expected, check the attributes.
Function output() is useful if you want to implement (and fully control) the sending of the message yourself.
Instead of using SetSignal() it is also possible to write the signal using $SignalName = value;
See this support note:
https://kb.vector.com/upload_551/file/SN-IND-1-011_InteractionLayer(1).pdf
You may have to guess and experiment a bit. In the DBC files provided by a customer I found attribute values that are not mentioned in this document.

How can I implement this type of redirect after post method in MVC

I am currently creating an MVC application that is currently getting a value from a post from a webhook. I think that the problem is that the application is getting the value from the POST verb but then it is not displaying it because the Get verb is being used to display the View so both Verbs are counter acting each other.
The webhook will fire A Json payload to my application successfully because I have code in it that will send the Json payload in a variable via email to my email account.
Dim body = issue.issue.key
mail.Body = body
That is in a try catch block because in order for it to have a value it must have a value in it and the application will perform the GET first, so there is a null value in the body variable, then it does the POST to get the value but it will not display the value, refreshing will just perform the GET preventing it from being displayed. How can I perform both actions at the same time so I can display a value in a ViewBag for example.
ViewBag.response = status + key
This is the type of structure that I would like to implement to try and fix the error but I do not know how to complete all of the steps:
This is what I have got so far:
The POST is coming in from a webhook and I am reading it like this.
Dim reader As System.IO.StreamReader = New System.IO.StreamReader(HttpContext.Request.InputStream)
Dim rawSendGridJSON As String = reader.ReadToEnd()
Dim tempVar As Rootobject = JsonConvert.DeserializeObject(Of Rootobject)(rawSendGridJSON)
System.Diagnostics.Trace.TraceError(rawSendGridJSON)
I am then trying to store the post values in a table like this:
Public Function CallBack(tempTable as temporaryTable)
Dim tempVar As Rootobject = JsonConvert.DeserializeObject(Of Rootobject)(rawSendGridJSON)
tempVar = temporaryTable.tempVar
I then save the new items in the actual table in the database, then I try to display it in a view on another page. This is not working correctly and the problem lies with this line, as the post is not being correctly read in at the right time. (The value is processing correctly as I can use an email method to send the variables in an email back to the application but this application needs to be real-time efficient code).
Is there a better way to use this method and how can I invoke this process that I want to do properly so that I can display the correct information?
Update
To clarify, there are two posts that are happening, the first one is when the user enters in information and submits it. This is then stored in a database and send to JIRA via email. Once JIRA receives the information, it is sends a HTTP POST webhook JSON Payload back to my application with updated information. I then have deserialized the JSON Payload into a variable called issueKey.
The problem is that on the View page that the information is sent to will automatically display a null value first before the value is sent to it, I want the application to work so that it will actually display/store in a database the values from the Webhook JSON Payload but I cannot figure out how to display the values.
I have now set up a communication channel from SignalR to my MVC application, at the moment it is being received by the MVC and I have set up a SignalR chat Hub in my MVC application, but I don't know how to integrate them, how can this be done?
As I understand it, there are two flows at work here. The user posts data, which triggers an email to Jira. Then sometime later (usually quite fast, but not always) JIRA triggers a webhook in the web application with some updated information, and you want to display this updated information to the user somehow, or at least inform the user when the updated information comes back from JIRA.
I would implement a standard Post-Redirect-Get for the user initiated part (as per br4d's comment). I.e. a post to store the data in the database and send email to jira, which returns a redirect to a get which shows the data stored in the database.
Now for the other part I would use signalr to set up some sort of communications channel to the user. The webook could then send a signal (of sorts) through the communication channel to the users browser and either display the data, or trigger a refresh of the page (if you are updating the database with data from Jira).
It is unclear if you are doing straigt mvc, or some sort of SPA application, but it is not really important. The users browser has no way of knowing about the webhook (which is a part of the webapplication and unrelated to the users session), and you need some sort of communication between the webapplication and the browser, and for this signalr is very very good.

A way to exclude self from Bonjour search results

When the same app acts as a Bonjour-enabled service and client at the same time, browsing for self-like services while listening on a socket, what's a good way to exclude self from service search results?
In your NSNetServiceBrowserDelegate you can just ask the incoming service if it is the same as the one you have published:
-(void)netServiceBrowser:(NSNetServiceBrowser *)netServiceBrowser didFindService:(NSNetService *)netService moreComing:(BOOL)moreComing
{
if ([netService isEqual:self.publishedNetService])
return;
…
}
In the server part, when I register my service with Bonjour, I generate a 10 character random alphanumeric string - a cookie. I make it a part of the advertised service name, as provided in call to [NSNetService initWithDomain:type:name:port:]. The resulting name is something like "MyApp on Joe's iPhone\txYbG56HjaE". The part before the tab character is for display, the part after is the cookie. I then store the cookie is a globally visible variable. Since server initialization takes place on app startup, the cookie value is available early on.
In the service discovery part, when I find a service, I check its name; if the cookie is the same as the stored global one, I skip this service. The idea is that other running instances of the program would have different cookie values, because randomness.
Naturally, when displaying discovered service names in the UI, I skip the part after the tab character.

Resources