Permanent Subscription MassTransit - no messages after restart - msmq

I'm hoping this will be an easy one for someone to point out that I've done something stupid!
I've recently tried to set up MassTransit on our systems here, but I'm having some issues with messages not being handled by my subscriber. The messages are handled fine up until the subscribing service gets restarted / redeployed, and after that they just don't work.
The Subscribing service is a Windows Service. I am using MSMQ along with the RuntimeServices bundled with MassTransit (v2.8).
I'm hoping I've missed something with regard to setting up a permanent subscription, but I've been hunting for more information without much luck.
Anyone have any idea if I've set something up wrong?
Here is the Initialization code:
Publishing Service
public static void Activate()
{
Bus.Initialize(bus =>
{
bus.UseMsmq(msmq => msmq.UseSubscriptionService("msmq://localhost/subscriptions"));
bus.UseControlBus();
bus.ReceiveFrom("msmq://localhost/our_webservice");
});
}
public static void Shutdown()
{
Bus.Shutdown();
}
Subscribing Service
private void ConfigureMessageBus()
{
Bus.Initialize(bus =>
{
bus.UseMsmq(msmq => msmq.UseSubscriptionService("msmq://localhost/subscriptions"));
bus.ReceiveFrom("msmq://localhost/commissionupdate_service");
bus.Subscribe(s => s.Consumer<CommissionUpdatedHandler>().Permanent());
});
}
protected override void OnStop()
{
Bus.Shutdown();
}
Please let me know if I can provide any more information that will help find the problem.
Thanks in advance!
Jim.

I don't know If this will help however We had a similar problem. In Our situation We had Azure Service Bus and unnecessary code in Publishing Service:
_busHandle = await _bus.StartAsync(cancellationToken).ConfigureAwait(false);
When I've removed it the problem was solved.

Related

Umbraco - when editor create content send email notification to admin

Is it possible?
I am an admin. I want to be notified by email when editor (or writer or whom ever with the access) creates some content (e.g. enters some News in News document type).
And how?
I use Umbraco 7.5
You need to code into Umbraco ContentService events.
The following should get you started. It will be triggered whenever an item is published.
Be careful what you wish for though. You may get a barrage of useless emails if somebody publishes a parent node along with all of its child nodes.
There are other events that you can hook into so please refer to documentation at https://our.umbraco.com/Documentation/Reference/Events/ContentService-Events-v7.
using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Publishing;
using Umbraco.Core.Services;
namespace My.Namespace
{
public class MyEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Published += ContentServicePublished;
}
private void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs<IContent> args)
{
foreach (var node in args.PublishedEntities)
{
// Your code to send email here
}
}
}
}
You can either write your own custom code by creating some event handlers, which is what #wingyip has recommended, or you can use built-in Umbraco notification functionality.
For the second built-in option, please see all the steps here on this post.

Permissions for ServiceStack Slack Logging

I'm currently trying out ServiceStack Logging with Slack, and altough it seems to work, I can't change the channels and name of the bot. I think it might have something to do with my Slack configuration, but since I didn't really use Slack before, I'm not sure how to set it up.
My logging config looks like this:
public override void Configure(Funq.Container container)
{
LogManager.LogFactory = new SlackLogFactory("https://hooks.slack.com/services/[...]", debugEnabled: true)
{
DefaultChannel = "logs",
ErrorChannel = "errorlogs",
BotUsername = "ServiceStack Logger"
};
SetConfig(new HostConfig
{
DefaultContentType = MimeTypes.Json
});
}
So, the logging works, but the username is not set correctly (instead, it's the apps name) and it only posts to the channel I specified when creating the WebHook. What do I need to adjust?
Edit: I access the logger like this:
public static ILog Log = LogManager.GetLogger(typeof(BroadcastService));
public object Get(ConnectionTest request) {
Log.Info(String.Format("Info Logged: {0}", DateTime.Now.ToShortTimeString()));
// ...
}
When using the ServiceStack Slack logger, to enable channel overrides, it needs to be used with an Incoming Web Hook.
https://api.slack.com/incoming-webhooks
As Slack API docs state, if the integration is trying to work with a Slack App, these overrides will be ignored.

What is best apprach to attempt multiple times same RPC call

What is best way to attempt multiple time same RPC call while failing RPC call?
just example: Here one case like if RPC get failed due to network connection, it will catch in onFailure(Throwable caught).
Now here it should recall same RPC again for check network connection. The maximum attempt should be 3 times only then show message to user like "Network is not established"
How can I achieve it?
Some couple of thoughts like call same rpc call in onFailure but here request become different.but I want same request have a three request and it is not good approach and I don't know if any good solution for it.
Thanks In Advance.
Use a counter in your AsynCallBack implementation. I recommend as well to use a timer before requesting the server again.
This code should work:
final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
final String textToServer = "foo";
greetingService.greetServer(textToServer, new AsyncCallback<String>() {
int tries = 0;
public void onSuccess(String result) {
// Do something
}
public void onFailure(Throwable caught) {
if (tries ++ < 3) {
// Optional Enclose the new call in a timer to wait sometime before requesting the server again
new Timer() {
public void run() {
greetingService.greetServer(textToServer, this);
}
}.schedule(4000);
}
}
});
#Jens given this answer from Google Groups.
You could transparently handle this for all your requests of a given GWT-RPC interface by using a custom RpcRequestBuilder. This custom RpcRequestBuilder would make 3 request attempts and if all 3 fail, calls the onFailure() method.
MyRemoteServiceAsync service = GWT.create(MyRemoteService.class);
((ServiceDefTarget) service).setRpcRequestBuilder(new RetryThreeTimesRequestBuilder());
The custom RequestBuilder could also fire a "NetworkFailureEvent" on the eventBus if multiple application components may be interested in that information. For example you could overlay the whole app with a dark screen and periodically try sending Ping requests to your server until network comes back online. There is also the onLine HTML 5 property you can check, but its not 100% reliable (https://developer.mozilla.org/en-US/docs/Web/API/window.navigator.onLine)

CometD Subscription Listeners

I’m having a problem processing Subscription Requests from Clients and carrying out some processing based on the request. I’d like to be able to invoke a method and carry out some processing when an incoming subscription request is received on the Server. I’ve had a look at the following CometD documentation and tried the example outlined in “Subscription Configuration Support” but I’m not having much luck.
http://www.cometd.org/documentation/2.x/cometd-java/server/services/annotated
I’ve already created the Bayeux Server using a Spring Bean and I’m able to publish data to other channel names I’ve created on the Server side. Any help or additional info. on the topic would be appreciated!
The code example I’m using:
#Service("CometDSubscriptionListener")
public class CometDSubscriptionListener {
private final String channel = "/subscription";
private static final Logger logger = Logger.getLogger(CometDSubscriptionListener.class);
private Heartbeat heartbeat;
#Inject
private BayeuxServer bayeuxserver;
#Session
private ServerSession sender;
public CometDSubscriptionListener(BayeuxServer bayeuxserver){
logger.info("CometDSubscriptionListener constructor called");
}
#Subscription(channel)
public void processClientRequest(Message message)
{
logger.info("Received request from client for channel " + channel);
PublishData();
}
Have a look at the documentation for annotated services, and also to the CometD concepts.
If I read your question correctly, you want to be able to perform some logic when clients subscribe to a channel, not when messages arrive to that channel.
You're confusing the meaning of the #Subscription annotation, so read the links above that should clarify its semantic.
To do what I understood you want to do it, you need this:
#Service
public class CometDSubscriptionListener
{
...
#Listener(Channel.META_SUBSCRIBE)
public void processSubscription(ServerSession remote, ServerMessage message)
{
// What channel the client wants to subscribe to ?
String channel = (String)message.get(Message.SUBSCRIPTION_FIELD);
// Do your logic here
}
}

Overrided broadcast(Object message, GwtAtmosphereResource resource) method in Atmosphere with GWT not working

We are trying to handle a scenario that when a user in quitting a room ,we send a message using MetaBroadcaster to all room .We implemented this feature by override broadcast method of AtmosphereGwtHandler .
The feature is good when we testing in development mode, but when we test it in Jetty8 production mode, telling by log, the override method is void which never get called.
So anybody know what's wrong with it, or do we have a better solution to this feature.
here is our code snippet:
public class ChatHandler extends AtmosphereGwtHandler {
...
#Override
public void broadcast(Object message, GwtAtmosphereResource resource) {
MsgType msgtype=((ChatMessage)message).getMsgtype();
if(msgtype==MsgType.Broad){
MetaBroadcaster.getDefault().broadcastTo(((ChatMessage)message).getChanel(), message);
System.out.println("Doing to all room);
}else{
super.broadcast(message, resource);
System.out.println("Doing to myself);
}
}
}
Can't really give an answer on the info provided.
Where have you configured your handler?
web.xml or atmosphere.xml
What servlet are you using Meteor/Atmosphere?
What version of Atmosphere?