Esempio n. 1
0
        public static IApplicationBuilder UseRabbitMq(this IApplicationBuilder app, Action <IMessageConfiguration> config)
        {
            Listener = (RabbitMqListener)app.ApplicationServices.GetService(typeof(RabbitMqListener));
            var lifetime = (IApplicationLifetime)app.ApplicationServices.GetService(typeof(IApplicationLifetime));

            lifetime.ApplicationStarted.Register(() => Listener.Register(config));
            lifetime.ApplicationStopped.Register(Listener.Unregister);

            return(app);
        }
        public async Task RabbitMqBus_PublishSubscribe_Test()
        {
            var options          = CreateOptions();
            var logger           = CommonUtils.CreateLogger <RabbitMqBus>();
            var rabbitMqBus      = new RabbitMqBus(options, logger);
            var rabbitMqListener = new RabbitMqListener(options, logger);

            var message = new TestMessage
            {
                Id     = "1",
                String = "Test string",
            };

            var         count  = 0;
            TestMessage result = null;

            rabbitMqListener.Subscribe("test", (TestMessage m) =>
            {
                result = m;
                return(Task.FromResult(count++));
            }, InteractionType.PublishSubscribe);

            var         count2  = 0;
            TestMessage result2 = null;

            rabbitMqListener.Subscribe("test", (TestMessage m) =>
            {
                result2 = m;
                return(Task.FromResult(count2++));
            }, InteractionType.PublishSubscribe);

            await rabbitMqBus.Publish("test", message, InteractionType.PublishSubscribe);

            await rabbitMqBus.Publish("test", message, InteractionType.PublishSubscribe);

            await TimeSpan.FromSeconds(1)
            .StopOnCondition(TimeSpan.FromMilliseconds(100), () => count >= 2 && count2 >= 2);

            count.ShouldBe(2);
            result.ShouldNotBeNull();
            result.Id.ShouldBe(message.Id);
            result.String.ShouldBe(message.String);

            count2.ShouldBe(2);
            result2.ShouldNotBeNull();
            result2.Id.ShouldBe(message.Id);
            result2.String.ShouldBe(message.String);
        }
Esempio n. 3
0
        public static int Main(string[] args)
        {
            try
            {
                //string mirthhostname = "fabricrealtimerabbitmq.eastus.cloudapp.azure.com";
                string mirthhostname = "fabricrealtime.eastus.cloudapp.azure.com";

                if (args.Length < 1)
                {
                    // host was not passed on the command line
                    Console.WriteLine("Enter host to connect to:");
                    mirthhostname = Console.ReadLine();
                }
                else
                {
                    mirthhostname = args[0];
                }

                Console.WriteLine($"Connecting to host: {mirthhostname}");

                string rabbitmqhostname = mirthhostname;

                RabbitMqTester.TestSecureConnectionToRabbitMq(rabbitmqhostname);

                IRabbitMqListener rabbitMqListener = new RabbitMqListener();

                MirthTester.TestSendingHL7(mirthhostname, rabbitMqListener);

                //var rabbitMqListener = new RabbitMqListener();

                //rabbitMqListener.StartListening(mirthhostname);

                Console.WriteLine("Press Enter to exit");

                Console.ReadLine();

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
    public void ConfigureServices(IServicecollection services)
    {
        services.Add.... // All your stuff
        // If this service will also publish events, add that Service as well (scoped!)
        services.AddScoped <IMeshEventPublisher, RabbitMqEventPublisher>(s =>
                                                                         new RabbitMqEventPublisher(rabbitConfig));

        // Since this service will be a singleton, wait until the end to actually add it
        // to the servicecollection - otherwise BuildServiceProvider would duplicate it
        RabbitMqListener rabbitMqListener = new RabbitMqListener(rabbitConfig,
                                                                 services.BuildServiceProvider());
        var nodeEventSubs = Configuration.GetSection(
            $"RabbitMQ:SubscribedEventIds:ServiceA").Get <string[]>();

        // Attach our list of events to a handler
        // Handler must implement IMeshEventProcessor and does have
        // access to the IServiceProvider so can use DI
        rabbitMqListener.Subscribe <ServiceAEventProcessor>(nodeEventSubs);
        services.AddSingleton(rabbitMqListener);
    }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Realtime tester using .Net Framework 4.6.1");

            //string mirthhostname = "fabricrealtimerabbitmq.eastus.cloudapp.azure.com";
            string mirthhostname       = "fabricrealtime.eastus.cloudapp.azure.com";
            string certificatepassword = "";

            if (args.Length < 1)
            {
                // host was not passed on the command line
                Console.WriteLine("Enter host to connect to:");
                mirthhostname = Console.ReadLine();
                Console.WriteLine("Enter certificate password:"******"Connecting to host: {mirthhostname}");

            string rabbitmqhostname = mirthhostname;

            RabbitMqTester.TestSecureConnectionToRabbitMq(rabbitmqhostname);

            IRabbitMqListener rabbitMqListener = new RabbitMqListener();

            MirthTester.TestSendingHL7(mirthhostname, rabbitMqListener);

            //var rabbitMqListener = new RabbitMqListener();

            //rabbitMqListener.StartListening(mirthhostname);

            Console.WriteLine("Press Enter to exit");

            Console.ReadLine();
        }
Esempio n. 6
0
        private static IUnityContainer ConfigureContainer(IConfiguration cfg)
        {
            var c = new UnityContainer();

            var qos = cfg.GetSection("RabbitMq:MqQos").Get <MqQos>();

            _client = new RabbitMqClient(qos);
            c.RegisterInstance <IRabbitMqClient>(_client);
            _listener = new RabbitMqListener <MqMessage <string> >(_client);
            c.RegisterInstance <IRabbitMqListener>(_listener);

            c.RegisterType <IEventHandler, EmptyHandler>("empty");
            c.RegisterType <IEventHandler, MovementDetectedHandler>("vision.evt.detected-movement",
                                                                    new PerResolveLifetimeManager(),
                                                                    new InjectionConstructor(c.Resolve <IRabbitMqClient>()));
            c.RegisterType <IEventHandler, FaceDetectedHandler>("vision.evt.detected-face",
                                                                new PerResolveLifetimeManager(),
                                                                new InjectionConstructor(c.Resolve <IRabbitMqClient>()));

            return(c);
        }