Update body of a "FailedMessages"-document in ravendb (servicecontrol instance ) - nservicebus

I want to be able to retry a failed NServicebus message but with an updated body.
I have successfulle updated the body tag in ravendb (the servicecontrol instance) of a "FailedMessages" Document
but
the api still returns the old body (from the bodyUrl). So when i retry the message from our custom document viewer the body is still the old when reaches the Handler.
Is it possible to update the body?
-EDIT-
When you do a retry using the Servicecontrol API. Is it the message that is in the error queue that is resent or is it data collected from the servicecontrol ravendb instance that are put together and sent?

It is not possible to update the body of a message, it goes against the basic principle of messages are immutable...
If there is a business reason to modify the data then it should be done by your application logic i.e. a reconciliation process.
Make sense?
EDIT:-
Error messages are processed from the error queue and stored in a RavenDB document, when a retry or a retry batch is invoked the message is composed and sent to the original endpoint that was processing the field message. Just to be clear.
Please note: ServiceControl's API is not a public and supported API...

I just managed to update the body of a message. It is possible after all.
Here is some sourcecode from ServiceControl:
DocumentStore.DatabaseCommands.PutAttachment("messagebodies/" + bodyId, null, bodyStream, new RavenJObject
{
{"ContentType", contentType},
{"ContentLength", bodySize}
});
Previously I tried to update the FailedMessage document which has a body tag. But I needed to update the Attachment. The bodyId in the above code is not the UniqueMessageId but MessageId found in ProcessingAttempts -> MessageMetadata -> MessageId.

Related

Capture start of long running POST VB.net MVC4

I have a subroutine in my Controller
<HttpPost>
Sub Index(Id, varLotsOfData)
'Point B.
'By the time it gets here - all the data has been accepted by server.
What I would like to do it capture the Id of the inbound POST and mark, for example, a database record to say "Id xx is receiving data"
The POST receive can take a long time as there is lots of data.
When execution gets to point B I can mark the record "All data received".
Where can I place this type of "pre-POST completed" code?
I should add - we are receiving the POST data from clients that we do not control - that is, it is most likely a client's server sending the data - not a webbrowser client that we have served up from our webserver.
UPDATE: This is looking more complex than I had imagined.
I'm thinking that a possible solution would be to inspect the worker processes in IIS programatically. Via the IIS Manager you can do this for example - How to use IIS Manager to get Worker Processes (w3wp.exe) details information ?
From your description, you want to display on the client page that the method is executing and you can show also a loading gif, and when the execution completed, you will show a message to the user that the execution is completed.
The answer is simply: use SignalR
here you can find some references
Getting started with signalR 1.x and Mvc4
Creating your first SignalR hub MVC project
Hope this will help you
If I understand your goal correctly, it sounds like HttpRequest.GetBufferlessInputStream might be worth a look. It allows you to begin acting on incoming post data immediately and in "pieces" rather than waiting until the entire post has been received.
An excerpt from Microsoft's documentation:
...provides an alternative to using the InputStream propertywhich waits until the whole request has been received. In contrast, the GetBufferlessInputStream method returns the Stream object immediately. You can use the method to begin processing the entity body before the complete contents of the body have been received and asynchronously read the request entity in chunks. This method can be useful if the request is uploading a large file and you want to begin accessing the file contents before the upload is finished.
So you could grab the beginning of the post, and provided your client-facing page sends the ID towards the beginning of its transmission, you may be able to pull that out. Of course, this would be reading raw byte data which would need to be decoded so you could grab the inbound post's ID. There's also a buffered one that will allow the stream to be read in pieces but will also build a complete request object for processing once it has been completely received.
Create a custom action filter,
Action Filters for executing filtering logic either before or after an action method is called. Action Filters are custom attributes that provide declarative means to add pre-action and post-action behavior to the controller's action methods.
Specifically you'll want to look at the
OnActionExecuted – This method is called after a controller action is executed.
Here are a couple of links:
http://www.infragistics.com/community/blogs/dhananjay_kumar/archive/2016/03/04/how-to-create-a-custom-action-filter-in-asp-net-mvc.aspx
http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/understanding-action-filters-vb
Here is a lab, but I think it's C#
http://www.asp.net/mvc/overview/older-versions/hands-on-labs/aspnet-mvc-4-custom-action-filters

Message Enricher in Mule

Trying to understand when to use Message Enricher in Mule? Can someone explains with real usage would be great. I already gone through mule documentation examples
Mule message enricher is best used in the case when you do not to lose your existing payload.
For example, let's consider, you need to call a DB in the middle of the flow and by doing this you will loose your current payload with the data from the DB and you don't want this to happen.
So, here you need your DB component wrapped with message enricher. By doing that you will get the data from DB as well as you will not lose your existing current payload.
<enricher target="#[flowVars.recordFound]" doc:name="Message Enricher">
<db:select config-ref="Derby_Configuration1" doc:name="DB_Details">
<db:parameterized-query><![CDATA[select * from Table1]]></db:parameterized-query>
</db:select>
</enricher>
Since message enricher takes a copy of the current payload, your existing payload will not lost
For more idea you can refer here:- http://www.slideshare.net/anir37/mule-message-enricher
Message Enricher will be used to store the data and to check that data in future processing like if you have to do batch processing so that it has to check the data whether present or not in first batch, if not we can insert that data in second batch.
It is like enrich the message which does not have in source system.
One common scenario involves the need to enrich an incoming message with information that isn’t provided by the source system. You can use a content enricher if the target system needs more information than the source system can provide.
Consider a message from a source system contains a zip code but the target system needs the two letter state. A message enricher can be used to lookup the state using the zip code from an enrichment resource. The enricher calls out to the enrichment resource with the current message (containing the zip code) then enriches the current message with the result.
This is a very simple flow with one-way inbound and outbound endpoints, and which acts as part of an order processing pipeline. This flow uses an enricher to add a state flow variable to the current message with the state that the stateLookup endpoint returns. The ‘target’ attribute defines how the current message is enriched using a MessageEnricher which uses the same syntax as expression evaluators.
Mule Enricher is a component, whole idea of using an enricher is to maintain the payload transaction intact and use it's content to apply some logic and store the result in a variable.
e.g. can be a xml payload, used to derive a complex logic result like discount calculation and then result of it can be stored in a variable and can be used further.
To add to these answers, you may also set the returning message (e.g. payload) to either payload, flow variables and outbound properties by simply defining the source and target within the Message Enricher.
The main purpose of the Message Enricher in Mule is to carry the same payload even after calling another flow by using flow reference.
Use Case: If you wanna use the same payload data through out the flow then you should go for Message Enricher
As you can see in the attached screenshot, here I have two flow references one is under Message Enricher i.e the Message Enricher flow reference will prevent the payload to be overridden by the payload from the referenced flow(overridenFlow), the original payload is maintained so that it can be used further
enter image description here
After second flow reference the payload is overridden and original payload can't be accessed further.
Message enricher is mainly used to extract something(eg. xpath) from payload and store it into flow/session variable, without actually changing the payload.
More advantages:
1) The source can be anything(i.e. payload, variables etc)
2) The source can also be modified to be able to extract info from it.
3) Multiple sources and target option is also available.
Also, as only one component can reside inside Message Enricher. Use of processor chain is recommended if more components are needed to reside inside Message Enricher.
Message Enricher in Mule is used to carry the same payload even after calling another flow by using flow reference.
Example use case: If you are taking data from some SaaS application and then want to store that data in Database, such that there is no duplicate entry in the Database. In this case you can check for Duplicate Data with the help of message Enricher before inserting it into Database.
Message enricher is one of the important components with Mulesoft. There are various scenarios in which you can use the message enricher component.
When synchronizing data between data sources, you often check to see if a record already exists in the target resource.
If you simply add an endpoint to query the target resource first before adding it, the response will become the payload. This is not what you want!
You want the external call to act as an enrichment of the existing message with the original payload retained.
Message Enricher in Mule is used to carry the same payload even after calling another flow by using flow reference.

NServicebus: reply message in case of exception

I have an endpoint which receives messages and creates a saga in order to be able to response to that corresponding message at a later point in time. The message contains some xml document and this xml doc will be validated within this message handler. If we catch some validation errors, we create a message response (no saga involved) to inform the originating endpoint that something with the xml doc was wrong. In the case of a validation error, the saga is not stored as expected and as required. But I still want to reply to the originating endpoint. The problem is, that nservicebus also does a rollback on the reply.
Is there a way to go? I tried to wrap the reply into a new transaction scope, but this did not work:
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
this.bus.Reply(message);
scope.Complete();
}
Any advice? Thanks in advance
Additional Information:
The orginal problem was that I did not throw (or rethrow) any exception but replying
to the originator in the catch section (I know its bad design).
The Saga is stored with a unique attribute applied on a id, which comes from the originating endpoint. And since I did not throw or pass any exception in the reply case (validation error occured), nservicebus always stored the saga. If the originating endpoint corrects the xml so that this is valid and resends a message (with the same id) nservicebus tries to store a new saga with the same id (causes concurrency exception on ravenDB because the saga with that unique property already exists). As a quick fix, I want to change the unique property and use instead the message id as the unique prop. In that case, I am sure that the message id is always unique and a saga concurrency exception could not happen again. Do you know if that causes any side effects?
You may be able to leverage the message handler pipeline. The first handler in your pipeline could do the validation and any response if necessary. During the validation, do not throw an exception, just reply. The second handler could initiate the Saga and set the state to be "Invalid" or something like that. My assumption is that you will get another request with valid data and then you will follow the "normal" process and set the state to "Valid" and continue on.

EventNotification in DocuSign SOAP based API

I am using EventNotification with DosuSign SOAP based API. The problem is i am not received any Request on the URL (that i mentioned in the definition of Event Notification) when any event occurs for Envelope.
Following are my code snippet: (here i required notification when envelope is completed)
Dim EnvelopeNotificationURL As String = "https://{my url}"
Dim EventNotifi As New EventNotification
EventNotifi.URL = EnvelopeNotificationURL
EventNotifi.LoggingEnabled = True
'Defining Envelope Events
Dim envEvent(0) As EnvelopeEvent
envEvent(0) = New EnvelopeEvent
envEvent(0).EnvelopeEventStatusCode = EnvelopeEventStatusCode.Completed
EventNotifi.EnvelopeEvents = envEvent
NewEnvelope.EventNotification = EventNotifi
'// Here NewEnvelope is an instance of Envelope Class.
There are at least a couple of possibilities here:
The event notification portion of your XML Request isn't correct/complete. I'd suggest that you update your question to include a trace of the complete XML Request that's being sent to the server (you can easily generate this trace using Fiddler or a similar tool), so that we can examine the full XML request and rule out any issues with its format/contents.
The XML Request format/contents is fine, and Connect is attempting to send the message to your listener when the Envelope is Completed, but there's an issue preventing the message from being delivered to your listener. I'd suggest that you check the DocuSign Connect Logs (in the DocuSign web console) to determine: 1) if messages are being sent and 2) if there are issues with the message reaching the listener endpoint. The Connect Service guide (http://www.docusign.com/sites/default/files/DocuSign_Connect_Service_Guide.pdf) contains information about how to view the logs.
If you can update your question with information about what you're seeing in the Connect log file, and also include a trace of the full XML request that's going to the server, I'll update this answer with additional feedback.

Create WCF addressing headers for reply message

I have a generic service with this interface
[OeprationContract(Action="*", ReplyAction="*")]
Message ProcessMessage(Message message);
In the implementation, I have to set up the headers of the reply message.
Is there a way to create the right addressing headers from the input message or do I have to set everything manually (i.e. copy In.replyTo to out.To, copy In.messageId to out.MessageId, ...)
Thanks
You'll need to do it manually; when you declare an operation taking an returning a Message object you're basically telling WCF that you want total control over the message, so no correlation between request and reply will be done for you.