How to defer an event in NServiceBus 6.0? - nservicebus

We're using NserviceBus as our messaging infrastructure with RabbitMQ as the transport.
I'm trying to upgrade to NServiceBus 6.0 from 5.* version. In 5.0, we could defer events using "Bus.Defer()". But it seems like in 6.0 we can defer only messages but not events ??
If I use below code with message being an "event", I get an error saying that events should be published.
var sendOptions = new SendOptions();
sendOptions.DoNotDeliverBefore(DateTimeOffset.Now.AddMinutes(30));
sendOptions.RouteToThisEndpoint();
return context.Send(message, sendOptions);
but context.Publish(message, new PublishOptions()) method takes in "PublishOptions" which does not have an option to defer.
Am I missing something here ? Appreciate if someone could help.

Some changes are not immediately effective, so we will have to defer some of those events.
The publisher should not be constrained by any of the subscribers.
Is it correct to assume that Product Authoring system publishes ProductDataUpdate events regardless of when the actual effective date will take place? In such case, you are already notified about a decision that was made. What are you, as a subscriber, going to do with it is a different thing and entirely internal.
You could send a command, for the sake of this discussion call it UpdateProductCost, that would be a delayed message if EffectiveDate is in the future. Otherwise, it's an immediate command.

I've got an answer in another forum and I think it is the most relevant, So posting it here so that it could help someone in future. Thanks to Daniel Marbach
https://groups.google.com/forum/#!topic/particularsoftware/ivy1wdsycT8
Bus.Defer in v5 was internally always doing a send operation. It seems the difference to v6 is that it automatically disabled the messaging best practices. You can achieve the same by calling
var sendOptions = new SendOptions();
sendOptions.DoNotDeliverBefore(DateTimeOffset.Now.AddMinutes(30));
sendOptions.RouteToThisEndpoint();
sendOptions.DoNotEnforceBestPractices();
return context.Send(message, sendOptions);
https://docs.particular.net/nservicebus/messaging/best-practice-enforcement

Related

Whats the best pattern/practise to work with WebFlux ClientResponse?

There are a lot of articles about using .exchange() and most of them recommend to close connection using
bodyToMono*, toEntity*, or just ClientResponse.close() or sometimes ClientResponse.dispose()
I am a little bit confused because ClientReponse interface in my project (spring-webflux:5.1.9.Release) doesn't have a method close();.
I need to check httpStatus (that's the only reason why I am using .exchange() but not .retrieve()), there is also some logic with "bad" httpStatus (I am throwing custom error and then process it in .onErrorResume() block)
So what is the best practise to work with clientResponse()?
If the only problem is that the App doesn't know when it should close the connection, will .exchange().block() automatically close the connection ?
If I should use .close() - how should I get this method ? Maybe I should use another version of spring-webflux ?
Or maybe there is another best way to retrieve response body and status in spring-webflux?
I dont think there is anything as "best practice" in this scenario . It totally depends on your requirements. Like you are throwing custom error on 4xx status, that's why you are using exchange.
Regarding ClientResponse.dispose() / ClientResponse.close() there is no such method in the documentation.
This is from the official doc

Mule Web Service Consumer Warning : Operation Messages With More then 1 Part Are Not Supported

Hi I am working with Mule Web Service Consumer and i was trying to call operation with Multiple Parameters it is warning me that
Warning : Operation Messages With More then 1 Part Are Not Supported
I just want to pass multiple parameters to access my SOAP method to achieve the task.
Is this the problem with Web Service Consumer or is their any way to deal with this.
I'm afraid this is a known limitation of the web services consumer. However you can accomplish this with the cxf component.
I having the same issue and found some information around it ...
There is a improvement logged in JIRA, may help if you vote for it :)
This link suggests that you can still use WSConsumer but need to do some hand crafting of the request XML ... I could not understand what that exactly it meant so if anyone has an example on it would be great
PS: The problem I had with using CXF component is that it does not play well with the new Dataweave transformer as the Dataweave needs to be placed within the response block and from there it cannot datasense the response coming out from the CXF component
The Solution here is very simple. You just have to comment other messages and then load metadata for non-commented message (for one which you're trying to load metadata). Repeat this procedure for all the other messages and you're good to go.
Hope this helps !

How to simulate an uncompleted Netty ChannelFuture

I'm using Netty to write a client application that sends UDP messages to a server. In short I'm using this piece of code to write the stream to the channel:
ChannelFuture future = channel.write(request, remoteInetSocketAddress);
future.awaitUninterruptibly(timeout);
if(!future.isDone()){
//abort logic
}
Everything works fine, but one thing: I'm unable to test the abort logic as I cannot make the write to fail - i.e. even if the server is down the future would be completed successfully. The write operation usually takes about 1 ms so setting very little timeout doesn't help too much.
I know the preffered way would be to use an asynch model instead of await() call, however for my scenario I need it to be synchronous and I need to be sure it get finnished at some point.
Does anyone know how could I simulate an uncompleted future?
Many thanks in advance!
MM
Depending on how your code is written you could use a mock framework such as mockito. If that is not possible, you can also use a "connected" UDP socket, i.e. a datagram socket that is bound to a local address. If you send to a bogus server you should get PortunreachableException or something similar.
Netty has a class FailedFuture that can be used for the purpose of this,
You can for example mock your class with tests that simulate the following:
ChannelFuture future;
if(ALWAYS_FAIL) {
future = channel.newFailedFuture(new Exception("I failed"));
else
future = channel.write(request, remoteInetSocketAddress);

Integrating with nservicebus

I need to integrate a .net2.0 app with nservicebus. Actually, I just need that this .net2.0 sends a message to a nservicebus queue.
Should I just create it by myself?
Theres any trick I should watch out, so when I upgrade to, lets say, nservicebus4 it wont break ?
using .net 2.0 will be a problem with trying to reference nservicebus. i don't think there is any straightforward way to reference nservicebus from a 2.0 application (outside of using a very old version, which would have problems too).
the shortest path would probably be to upgrade the framework version to 4.0. why not just do this? if you're talking about making changes and sending messages, you must have access to the source code and the ability to change it.
next after that might be to serialize a message yourself and send it with system.messaging. i think this is what you mean by "create it by myself." you'd definitely want to test that your messages still work if updating to another version of nservicebus on the handling side. udi is insistent on backward compatibility in updating versions of software, so i'd expect nservicebus would exhibit this probably and that your messages would still work, but you would want to make sure.
To "integrate" an app with NServiceBus simply include binary references to NServiceBus.dll, NServiceBus.Core.dll, and NServiceBus.Host.exe in your solution.
Try downloading the samples.

Process All Windows Messages Generated By A Compact Framework Application

Hoepfully someone can shed some light on a problem - I am trying to listen to\intercept all windows messages generated by an application and dispose of certain types, for example Notify or Gesture messages.
I have been reading articals on how to do this using the Microsoft.WindowsCE.Forms.MessageWindow and creating a class which inherits this, overrides the WndProc method but I have been unalbe to get this start listening\watching the message queue automatically when the application starts.
I know it is possible to do this with the OpenNetCF framework and the Application2 namespace however I would prefer not to use 3rd party software at the moment - no offence to the OpenNetCF guys.
Hopefully this makes sense. Also, i am using C#2.0 and Windows Mobile 6.5.
Thanks for your help,
Morris
The solution, then, is pretty simple - all you have to do is spend your time duplicating what the Smart Device Framework code is doing.
You need to create your own message pump via P/Invokes to GetMessage, TranslateMessage and DispatchMessage (it will look just like it does in C). Use this pump instead of calling Application.Run (so there can be no calls to Application.Run in your application).
Inside that new message pump insert your filtering logic.