public MsgNThenRabbitIntegration(ITestOutputHelper output)
        {
            _output = output;
            var serviceCollection = CreateServiceCollection();

            serviceCollection.AddSingleton <IMessageHandler, BlockMessageHandler>();
            var messageGroupHandler = Substitute.For <IMessageGroupHandler>();

            serviceCollection.AddSingleton <IMessageGroupHandler>(messageGroupHandler);

            var serviceProvider = serviceCollection.BuildServiceProvider();

            _messageHandler   = (BlockMessageHandler)serviceProvider.GetRequiredService <IMessageHandler>();
            _listener         = serviceProvider.GetRequiredService <IRabbitMqListener>();
            _andThenPublisher = serviceProvider.GetRequiredService <IMessageAndThenPublisher>();
            _rabbit           = serviceProvider.GetRequiredService <IConnection>();
            _output.WriteLine("Binding");

            _andThenPublisher.BindDirectQueue(ExchangeName, QueueName);
        }
Ejemplo n.º 2
0
        public static void TestSendingHL7(string mirthhostname, IRabbitMqListener rabbitMqListener)
        {
            // from http://www.mieweb.com/wiki/Sample_HL7_Messages#ADT.5EA01
            var message =
                @"MSH|^~\&|SENDING_APPLICATION|SENDING_FACILITY|RECEIVING_APPLICATION|RECEIVING_FACILITY|20110613083617||ADT^A01|934576120110613083617|P|2.3||||
EVN|A01|20110613083617|||
PID|1||135769||MOUSE^MICKEY^||19281118|M|||123 Main St.^^Lake Buena Vista^FL^32830||(407)939-1289^^^[email protected]|||||1719|99999999||||||||||||||||||||
PV1|1|O|||||^^^^^^^^|^^^^^^^^";

            // set up the queue first


            CancellationTokenSource tokenSource = new CancellationTokenSource();
            CancellationToken       token       = tokenSource.Token;

            var messageReceivedWaitHandle = new AutoResetEvent(false);
            var channelCreatedWaitHandle  = new AutoResetEvent(false);

            var task = Task.Run(() => rabbitMqListener.GetMessage(mirthhostname, token, messageReceivedWaitHandle, channelCreatedWaitHandle), token);

            // wait until the channel/queue has been created otherwise any message we sent will not get to the queue
            channelCreatedWaitHandle.WaitOne();

            var result = SendHL7(mirthhostname, 6661, message);

            // wait until the message has been received
            messageReceivedWaitHandle.WaitOne();

            // tell the other thread to end
            tokenSource.Cancel();

            // wait for other thread to end
            // ReSharper disable once MethodSupportsCancellation
            task.Wait();

            var r = task.Result;
        }
 public BackgroundServiceWrapper(IRabbitMqListener <TEvent> rabbitMqListener)
 {
     _rabbitMqListener = rabbitMqListener;
 }