0

I have a windows service. I using Topshelf. When started it is run a cs.Start() method.

        static void Main(string[] args)
        {
            var exitCode = HostFactory.Run(x =>
            {
                var assembly = new AssemblyInfo(Assembly.GetAssembly(typeof(Program)));

                x.Service<Services.Producer>(s =>
                {
                    s.ConstructUsing<Services.Producer>(cs => new Services.Producer(log));

                    s.WhenStarted(cs => cs.Start());
                    s.WhenStopped(cs => cs.Stop());
                });

                x.EnablePauseAndContinue();

                x.EnableShutdown();

                x.EnableServiceRecovery(r =>
                {
                    r.OnCrashOnly();

                    r.RestartService(delayInMinutes: 0);

                    r.RestartService(delayInMinutes: 1);

                    r.RestartService(delayInMinutes: 5);

                    r.SetResetPeriod(days: 1);
                });

                x.SetServiceName(System.Text.RegularExpressions.Regex.Replace(assembly.Product, @"\s+", ""));
                x.SetDisplayName(assembly.ProductTitle);
                x.SetDescription(assembly.Description);

                x.AfterInstall(p =>
                {
                    log.Info("xxxxxxxxxxx.");
                });

                x.AfterUninstall(() =>
                {
                    log.Info("xxxxxxxxxxxx.");
                });

                x.OnException(ex =>
                {
                    log.Error($"Error.", ex);
                });
            });
        }

Start() method call another method. Implementation this async method see below:

        public void StartAsync(INmsService nmsService)
        {
            try
            {
                if (!nmsService.IsStarted)
                {
                    var worker = new BackgroundWorker();
                    worker.WorkerSupportsCancellation = true;

                    worker.DoWork += (e, o) =>
                    {
                        try
                        {
                            nmsService.Start();
                        }
                        catch (Exception ex)
                        {
                            log.Error($"xxxx", ex);
                        }
                    };

                    worker.RunWorkerCompleted += (e, o) =>
                    {

                    };

                    worker.RunWorkerAsync();
                }
            }
            catch
            {
                throw;
            }
        }

Now nmsService.Start() code:

        public void Start()
        {
            try
            {
                factory = new NMSConnectionFactory(Settings.Endpoint);

                connection = factory.CreateConnection(Settings.UserName, Settings.Password);
                connection.ClientId = $"{Settings.Name}Service";

                session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                destination = SessionUtil.GetDestination(session, Settings.QueueName, DestinationType.Queue);

                producer = session.CreateProducer(destination);

                connection.Start();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

But, when to run implementation, this a exception is a rised:

"Could not create the IConnectionFactory implementation: CreateConnectionAsync method on Apache.NMS.ActiveMQ.ConnectionFactory type of Apache.NMS.ActiveMQ assembly, Version=1.8.0.0, Culture=neutral, PublicKeyToken=82756feee3957618 does not have an implementation."

Thank for help!

Jheferson
  • 61
  • 6
  • https://stackoverflow.com/questions/34438756/activemq-no-iconnectionfactory-implementation-found-for-connection – Hans Passant Nov 22 '21 at 21:43
  • No. This is not my problem. I created a project that implements NMS Connect. The parent project references this project. When done in this way, the exception informed is thrown. – Jheferson Nov 23 '21 at 12:58

1 Answers1

2

I don't know what exactly caused the error, but the solution I found was to revert the two dependencies Apache.NMS and Apache.NMS.ActiveMQ to previous versions. I had upgraded to v2.0.0 and v1.8.0. I've downgraded Apache.NMS to v1.8.0 and Apache.NMS.ActiveMQ to v1.7.2 and the problem was fixed.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Jheferson
  • 61
  • 6
  • YMMV but I was able to just downgrade `Apache.NMS` to `v1.8.1` and leave `Apache.NMS.ActiveMQ` at `v1.8.0` – sonyisda1 Jul 07 '22 at 19:18