Installing NServiceBus as a Windows Service with dependency on RavenDb - ravendb

When we install an NServiceBus 3.3.6 endpoint as a Windows service using the /install flag, it is automatically configured with a windows service dependency on Message Queuing.
However, even though our NServiceBus endpoints use RavenDb for persistence, the installer does not configure a service dependency on RavenDb. This means that when our server restarts most of our NServiceBus endpoints fail to start up due to the following exception:
System.InvalidOperationException:
The database {name} is currently being loaded, but after 30 seconds,
this request has been aborted. Please try again later, database loading continues.
Is there any way to tell NServiceBus to set up a dependency on RavenDb or is this something we have to configure manually, perhaps using INeedToInstallSomething<T>?

You can pass a dependencies list eg:
NServiceBus.Host.exe /install /dependsOn:"MSMQ,RavenDB"
The list needs to be comma delimmited.
In v4 the command line args are a bit different:
NServiceBus.Host.exe -install -dependsOn=MSMQ -dependsOn=RavenDB

Related

Error -1072824317 trying to use MSMQ with WCF

I have a Silverlight client which is talking to a WCF Service and performing some actions
Most of the time these actions will be quick, but often they wont be so I need a way of avoiding WCF timeouts by essentially passing the work onto its own "thread" server side and having a way for the client to know when the operation has completed
I have searched on here and found reference to the article below
http://msdn.microsoft.com/en-us/magazine/cc163482.aspx
I have downloaded the sample
It was targeting .NET 2 so I have updated it to 4.5 and the required IDesign folder didn’t exist in c:\program files so I have created it
Once I installed MSMQ and tried to run the client I get the error below
HResult=-1072824317
Message=An error occurred while opening the queue:Unrecognized error -1072824317 (0xc00e0003). The message cannot be sent or received from the queue. Ensure that MSMQ is installed and running. Also ensure that the queue is available to open with the required access mode
Does anyone know what the problem is here? I am very new to MSMQ
I notice that this code is very old (2006), so is there a better way of doing this nowadays?
Paul

Error in log after windows restart when subscriber is installed as a service

I'm using NserviceBus 2.0 with pub/sub mode.
My subscribers are installed as a windows service.
However after computer restart I always get the following problem in log : "Problem in peeking a message from queue: ServiceNotAvailable".
After digging into source code I found that this is NserviceBus custom error and it occurs in MsmqTransport class. It seems like my subscriber's service is started before Msmq service. Bus this should be impossible because subscriber's service has Msmq as dependency.
After some time service is starting and working correctly. But I have several megabytes of errors in log. And sometimes service is not even starting.
Can anyone help me? I'm using Windows 7. Msmq is installed with NserviceBus utils.
You need to configure your service to be dependent on the MSMQ service. This is should be automatically taken care of if you're using the NServiceBus host.
Installing a Windows Service with dependencies
Have seen the same problem. Actually the impact was even worse since we used log4net and SmtpAppender. Took down the mailserver, ouch! Seems like this is fixed in NSB 3. It sets number of workerthreads to zero and logs "please reboot service". You can even execute own code when the error occurs. Config with lambda using OnCriticalError. We ended up patching the NSB 2 code, since we havent upgraded to NSB 3 yet. Handling MSMQExceptions, logging and stopping the process on errorcode ServiceNotAvailable like they already do when you don't have correct rights to queue. You should probably stop the service on any MSMQExceptions exept IOTimeout.

Windows service connecting to other service over wcf crashes

I have two windows services. One ('server') acts as a WCF host to which the other ('client') connects. So I have configured a dependency from client to server. Both are also set up to start automatically.
When I start these services by hand, everything works fine. When I stop both services and tell client to start, then server will be started before client and all is fine.
However, when I reboot the machine only server is started.
When I add a diagnostic listener I see it got a TimeoutException with the helpful message:
The HTTP request to 'http://[server address]' has exceeded the allotted timeout of 00:00:00. The time allotted to this operation may have been a portion of a longer timeout.
At some other SO question there was an answer that claims WCF is probably confused about what went wrong and therefore starts lying about the timeout.
Did I perhaps miss a dependency for either service? Does WCF require something that hasn't or is being started when client is trying to contact server?
I think you should check your client service. On startup windows services are starting while network devices are still being initialized. Services should be ready to start without network and without any network device. Usual approach is to keep periodic retries to establish connection. You can do little experiment on your machine by uninstalling all network adapters and trying to start up your services.
Additional quick workaround you can do is to setup recovery options on your service -- for example you can configure it to restart service on crash after some timeout -- you can do this through UI in services.msc or in command line using 'sc config' command.
Configuring the dependency between the two Windows Services is not necessarily sufficient to avoid there being a race condition: i.e. to avoid the client service calling the WCF service before the server's WCF channel stack is fully initialised.
The service dependency just ensures that the Windows Service Control Manager won't start the client service process before the server Windows Service has notified the SCM that it has started. Whether this is sufficient depends on how you write the server.
If the server service starts a new thread on which to initialize the WCF stack, your OnStart method is probably returning before the WCF stack is ready for clients. There is then a race condition as to whether the client's first call will succeed.
On the other hand, if the server service does not return from OnStart (and thus doesn't notify the SCM that it has started) until the channel stack is fully open, the dependency removes the race condition, but there is a different pitfall: you need to beware that the SCM's own timeout for starting the Windows service is not triggered while waiting for the WCF stack to initialise, as might well happen on a reboot if the WCF service depends on the network stack, for example. If the server's OnStart does not return within the SCM's timeout, the SCM will not try to start the dependent client service at all, because it does not receive the server's start notification. (There will be a message in the Windows event log from the SCM saying that the server service didn't start within the expected time.) You can extend the SCM timeout by calling ServiceBase.RequestAdditionalTime while the WCF service is being initialised.
Either way, the client service really ought to be written so that it doesn't fail completely if the first WCF call doesn't succeed.
You don't actually say what binding you are using. If client and server services are always running on the same machine, as you seem to indicate, then consider using the NetNamedPipeBinding: then your service won't be dependent on initialization of networking resources and startup should be quicker.

WiX - Modifying an existing service to be dependent on the service I am installing

Using Wix3, its trivial to ensure that a windows service being installed is given a dependency on a service that is already installed on the target machine, but I need to do the opposite - i.e. as part of my install I need to modify the service dependencies of an existing service (i.e. already installed on the target machine), to ensure that that service is dependent on the service I am installing.
Is there a simple way to do this using WiX? or will I need to write a custom action?
Edit - The scenario is around a custom Windows Service that MS Office Communications Server will dispatch messages to. Once OCS is configured to dispatch to that service (and it is marked as a critical service) then that service must be up and running in order for the OCS service to start. So we need the dependency there to ensure our service starts before OCS, and we would usually add the dependency by hand following installation.
I know, it makes me shudder too.
Many thanks,
Paul
This is a form of a component rule violation because windows installer only creates services for keyfiles and you would be creating a duplicate component to control the service.
Basically your jacking with the attribute of a resource that belongs to a component that isn't your own. When this service was written, I'm guessing it had no idea about your service so how could it possibly have a dependency on your service?
What I'm really asking is what problem are you trying to solve? If you really must do it in WiX/MSI, your probably best off with a custom action to call into the service control manager and add the dependency. Just don't be suprised if whatever installed the service decides to undo your change because it doesn't match it's notion of how that service should be configured.

MSMQ backed WCF service hosted in a windows service fails on startup

I have a WCF service hosted in a Windows service that I set to Automatic so it will start automatically when the server is brought up. The service is endpoint is MSMQ backed.
When I start the service manually, everything is good. But when the service starts on bootup, I get a MSMQ exception:
System.TypeInitializationException: The type initializer for
'System.ServiceModel.Channels.Msmq' threw an exception. --->
System.ServiceModel.MsmqException: The version check failed with the error:
'The Message Queuing service is not available (-1072824309, 0xc00e000b)'. The
version of MSMQ cannot be detected All operations that are on the queued channel
will fail. Ensure that MSMQ is installed and is available.
at System.ServiceModel.Channels.MsmqQueue.GetMsmqInformation
(Version& version, Boolean& activeDirectoryEnabled)
at System.ServiceModel.Channels.Msmq..cctor()
--- End of inner exception stack trace ---
It seems like the MSMQ is not ready to be used before the service starts...is there a solution to this?
You need to add a dependency on MSMQ in your WCF service host. You can do this in the service installer:
ServiceInstaller serviceInstaller = new ServiceInstaller();
// Adding this property to your ServiceInstaller forces
// your service to start after MSMQ.
serviceInstaller.ServicesDependedOn = new string[] { "MSMQ" };
If you are not using a service installer, you can also add the MSMQ dependency for your service by editing the Windows registry, as described in "Microsoft Support: How to delay loading of specific services".