I am trying to run an NServiceBus solution containing several endpoint configs in one directory. I am executing the host.exe with (among other things) /endpointConfigurationType:"class, assembly".
The host correctly isolates itself to using only the one endpoint config, but then it appears to scan the directory anyway, loading and leveraging any NSB interfaces found in other DLLs that are used by the other services. For example, the IWantToRunAtStartup implementations in other endpoint DLLs are being executed even though I only expect NSB to care about interfaces found in /endpointConfigurationType.
What all steps are required to deploy an NSB solution to a flat folder structure, such that NSB will only concern itself with the endpoint it is told to execute?
See the "File Scanning" section of this page:
http://support.nservicebus.com/customer/portal/articles/856698-the-nservicebus-host
The following should work:
Configure.With(Assembly.GetExecutingAssembly())
.NinjectBuilder(kernel)
.FileShareDataBus(BasePath)
.UnicastBus()
.MsmqSubscriptionStorage()
.PurgeOnStartup(false)
.XmlSerializer()
.MsmqTransport();
Regarding the installation, just make sure you run /install for each /endpointConfigurationType, see http://support.nservicebus.com/customer/portal/articles/856698#installation
Related
I've gone through all the documentation and examples of setting up NServiceBuse in NetCore, however, all the examples have the configuration being done in the Program.cs (Host.CreateDefaultBuilder().UseNServiceBus()).
I would like to know if I can configure NServiceBus in the ConfigureServices method of Program.cs.
The reason is that in the HostBuilder I'm building up all of the IConfiguration options (e.g. reading from appsettings.json, EnvironmentVariables, AzureKeyVault, ConfigMaps, etc.) and the Logger implementation. By the time ConfigureServices is called, all of those have been resolved. I need to be able to get things like connection strings from the IConfiguration, and so I don't believe it will work to do it in the HostBuilder.
It looks like a lot of work might be being done under the covers to inject the IMessageSession and scan for IHandlMessages instances. That should be able to be done in the Service.
Edit: Forgot to add, because it is in the Program.cs and we are using Serilog, I do not have a LoggerFactory. The LoggerFactory is registered and injected by the Services, but I cannot get it at this point in startup.
Looks like this isn't an option. I was able to have a workaround to get it all working, which is just to put it in the Program() and just make sure it is called after all the other configuration is done. It doesn't seem ideal and seem to be an anti-pattern from where netcore 3 is going.
I'd like to add that this is a poor design choice. I should be able to register my stuff in startup and package scanning shouldn't be happening.
This is a neat project, but I think that for any non-trivial development it may be left lacking.
The reason is that I would like to have a web host with multiple endpoints and I cannot do that without running two full instances (https://docs.particular.net/samples/hosting/generic-multi-hosting/).
My workflow is
message comes in to do all the work
message #1 starts a saga with 100+ messages
each message publishes an update that it is done, so that the UI can check the status of the Saga
The messages from #3 are not handled until all 100+ messages are processed (FIFO).
What I'm wanting to do is have a second queue (we're using Azure service bus) to listen for the worker updates on and update the UI.
Although you already have a workaround I have build a similar setup as you described with with Serilog as logger and NServiceBus. You can access the configuration in Program.cs like so:
public static IHostBuilder CreateHostBuilder() =>
Host.CreateDefaultBuilder()
.ConfigureAppConfiguration()
.UseSerilog()
.UseNServiceBus(c => NServiceBusSetup.Configure(c.Configuration, c.HostingEnvironment))
In the self made method NServiceBus.Configure you can setup your endpoint.
I am attempting to host a Saga from one project in another project using NServiceBus 6 with SqlPersistence and SqlDialect.MsSqlServer. In most examples I have found, the Saga is contained in the same assembly as the hosting app, and perhaps this is why I am struggling.
When hosting everything in the same app, the NServiceBus.Persistence.Sql.MsBuild package correctly outputs Saga .sql files during the build and then picks these up and executes them on run. Using a separate app, only the Outbox, Subscription and Timeout .sql files are generated, not the Saga ones. The following entry is then logged on run:
INFO NServiceBus.Persistence.Sql.Installer Directory '[PATH]\SagaPersistence\Service\bin\Debug\NServiceBus.Persistence.Sql\MsSqlServer\Sagas' not found so no saga creation scripts will be executed.
A full VS 2017 repro may be found at https://github.com/WolfyUK/NServiceBusSagaSqlPersistence.
Firstly, is it a bad idea to host a Sagas from another service, rather than being self-hosted? If not, can someone advise the best way to resolve the SQL Persistence issue?
Can you add NServiceBus.Persistence.Sql.MsBuild to the Saga project? The scripts should then be found there. Unfortunately they're not copied to the host its folder, so you'll have to take them from there into production. Or have them generated by using EnableInstallers, like you're already doing.
Perhaps I'm missing something here and this question is maybe the same as this one so sorry for any duplication.
I have an MVC4 site that quite happily Sends() commands to my NServiceBus server. I now want the same MVC site to be able to subscribe to IEvents Publish()ed from the same NServiceBus server. But I just can't get it to work.
Messages are being published from the server and are showing in MSMQ but I can't get the MVC site to pick them up.
Is this possible with NServiceBus 3.3.5? And if so, how do I have to set up my MVC site to make it work?
Thanks in advance!
Edit: Here's the config I have in the MVC app:
Configure.With()
.Log4Net()
.StructureMapBuilder()
.MsmqTransport()
.IsTransactional(false)
.PurgeOnStartup(false)
.UnicastBus()
.LoadMessageHandlers()
.ImpersonateSender(false)
.JsonSerializer()
.CreateBus()
.Start(() => Configure.Instance.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install());
I don't have an EndpointConfig class that implements the IConfigureThisEndpoint or and AsA_ interfaces. I've tried adding one but it never gets called and I can't work out what the host would be or how to start the NServiceBus host application from the web app. Or even what context the host would run under if the code sits inside IIS (if that makes sense!).
My guess is you're missing the .LoadMessageHandlers() line in your fluent config after .UnicastBus() - that's the most common error that leads to self-hosted applications not processing messages sent to them.
If that's not the case, add your fluent config block to your question and we'll take a look.
Edit: After fluent config posted
My next guess is that you're declaring your serializer too late. The .UnicastBus() step is one of the last stops before "Let's start this thing!" I'm thinking perhaps by the time you've hit this point, the config has made the assumption you're going with the default XmlSerializer. Could you try moving the serializer line to right after .StructureMapBuilder() and see if that works better?
If that doesn't work I might consider using the .DefaultBuilder() momentarily just to rule out an problem with your IoC container.
In regards to your other comments, a self-hosted bus will never have an EndpointConfig. That's a pointer for endpoints hosted by the NServiceBus.Host.exe only.
I also suppose it's not completely obvious where you're calling this fluent config from. This code needs to be called once when the webapp is started up - usually from the application start method in the Global.asax. Because the webapp is in control, there's no automatic assembly scanning to find and wire up your NServiceBus pipeline like in the NServiceBus Host.
I´m creating a new WCF service. I initially had only three operations. But after some time I decided to add two more. This operations doesn't appear in the Microsoft test client, neither in the list of operations when I try to add a service reference from my WPF client. Also I tried to comment one of the initial operations. It still apears in the Microsoft test client and can be invoked. I Tried also delete the dlls generated by the service and regenerate again. No luck. There are some kind of "cache" where Visual Studio stores the WCF services libraries that I can delete?
UPDATE: I'm working with the service running in the ASP.NET devolopment server.
You need to understand the order in which things happen.
You change your code, adding methods with [OperationContract] on them, or removing them, or changing their parameters or return values.
You then must build your service, producing a .DLL that contains the changes.
You must then deploy the changed DLL to the server it's going to run on
You must then restart the service (this may happen automatically depending on the server. For instance, IIS will recycle the service when it sees that the DLL changed)
You must then update your client, either the WCF Test Client, or "Add Service Reference", or the equivalent.
This last will have the effect of sending a request to the service for the new metadata or WSDL. Only then can the client see the changes you made to the definition of the service.
I don't know why, but I created a new project and copied the definitions of the operations from the problematic project and the problem is gone. One case more for Microsoft mysteries.
Make sure you are updating the services after adding the new operations.
Also make sure they have the attribute [OperationContract].
One thing we have discovered is that when you deploy the dlls that they must be in the bin, and cannot reside in the debug or release folder.
For me worked: just rebuild the wcf project
Did you close the client connection in client side
as showing your service
class Test
{
static void Main()
{
LocationClient client = new LocationClient();
// Use the 'client' variable to call operations on the service.
// Always close the client.
client.Close();
}
}
SOLUTION HERE :
Make sure your dataContract does NOT contain any enum
(You can use integer instead)
Be sure to reference a project in the solution and not a dll on your disk
Remove your "bin" and "obj" folders
Recompile
In IIS recycle the application pool
In IIS restart your service
In IIS "Browse" your service
=> You got it
I've got a class library doing all my NHibernate stuff. It also handles all the mapping using Fluent NHibernate - no mapping files to deploy.
This class library is consumed by a number of apps, including a Windows Service running on my computer. Although it works fine in all my web apps, the Windows Service gets this when it tries to use NHibernate:
An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at Kctc.NHibernate.KctcSessionFactory.get_SessionFactory() in C:\Kctc\Trunk\Kctc.NHibernate\KctcSessionFactory.cs:line 28
...more stack trace...
I have checked for an InnerException and there doesn't appear to be one. I have no idea what the PotentialReasons collection is, and Google doesn't seem to be forthcoming either.
This is my dev machine, so when I'm working on my web apps they run locally (i.e. using the web server in Visual Studio). The fact that the Windows Service and my dev web apps are running on this same machine suggest it's not to do with trust settings or what have you.
Can anyone suggest what I should try? This is one of those ones where I'm so stumped I can't even think of how to get more information about the problem.
Just a wild guess. NHibernate picks up the hibernate.cfg.xml file from the execution directory. Did you configure the execution directory of the service that it can find this file?
I've found out what the problem is. The Service did not deploy with the required NHibernate.ByteCode.LinFu.dll.
I appear to have an ongoing problem with the Visual Studio compiler not always copying indirect dependencies (i.e. dlls required by class libraries required by the app) into the output folder during the build. I should have thought of this sooner really.
Thanks for racking your brains on my behalf guys.
I bet the name of the connection string is missing from the app.config. For me that message is almost exclusively a missing connection string.
Are you targeting the same database or could it be some sort of schema mismatch between databases?
Could it be authentication issues on the service like you use windows authentication where it can't be used (or the sql authentication that doesn't work)?
It's hard to tell when there is no code, just an exception!
EDIT Are you ever using HttpContext, HostingEnvironment or anything else specific to "web"?