How do I set CurrentMessageContext.TimeSent for testing in NServiceBus? - nservicebus

I'm testing an NServiceBus saga that sends a command. The command has an attribute that tracks the time an action was performed. The handler for the message assigns CurrentMessageContext.TimeSent to LastSentOn in the outgoing message.
When I try to test the outgoing message, LastSentOn always has the value DateTime.MinValue, so....
How do I set CurrentMessageContext.TimeSent for testing in NServiceBus?

Josh - this is not a direct answer to your question, but have you seen this?
http://github.com/NServiceBus/NServiceBus/issues/808
Looks like CurrentMessageContext.TimeSent has been deprecated and is now just a setting in the message headers. Perhaps you can use the header value instead.

Related

Can NServiceBus TimeToBeReceived be set on a per-message basis?

I've seen in the documentation that TimeToBeReceived can be set on a message class or on the endpoint itself. I have a message class that should use TimeToBeReceived, but I'd like to alter the specific length of time for each individual message. Is this possible? I would have thought the option would be in the SendOptions, but I don't see it there.
Since this was never officially answered, I suppose I'll do so myself. The answer is no, this functionality is not supported by NServiceBus.

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

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.

Where is the right place to add the user and time a command was issued in NServiceBus?

Some of my NServiceBus commands will need to track who issued the command and when. I'm very unsure as to the recommended way to implement this:
Should I create a base class MessageBase, add public Dictionary<string, string> Headers;, and implement IMutateOutgoingMessages?
Should it be added to the MessageContext? If so, how do I ensure the Bus adds it before every message (which needs the headers) is sent?
Is it already done and I just don't know how to access it? (It looks like the user is in the raw MSMQ message...)
NServiceBus already gives you the time the message was sent using the "NServiceBus.TimeSent" header.
Use the builtin NServiceBus headers dictionary and skip the MessageBase
Attaching user id is best done in a outgoing message mutator. Just grab the ID from eg the HttpContext and add it as a header.
http://support.nservicebus.com/customer/portal/articles/860492
To get the time (in your handler/saga):
Bus.CurrentMessageContext.TimeSent

If I set a header in a message handler in Nservicebus should the header value be available to downstream handlers?

I have a message type that is handled by two different handlers (with the order specified by ISpecifyMessageHandlerOrdering).
If I set a header inside the first handler, say message.SetHeader("SomeStatus", "value"); should I then be able to call message.GetHeader("SomeStatus") in the second hander and get the value set?
It's currently not working for me, GetHeader is just returning null, but I don't know if I'm doing something wrong or if this shouldn't work anyway.
I'm using nservicebus 3.2.5
You're right - this is a bug. Logged as #529 and will be fixed as part of the next release.
https://github.com/NServiceBus/NServiceBus/issues/529

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.