Esempio n. 1
0
 void CompleteSend(IAsyncResult result)
 {
     try
     {
         outputChannel.EndSend(result);
         outputChannel.Close();
     }
     finally
     {
         outputChannel.Abort();
     }
 }
Esempio n. 2
0
            public void Send(Message message, TimeSpan timeout)
            {
                TimeoutHelper  timeoutHelper = new TimeoutHelper(timeout);
                IOutputChannel outputChannel = ValidateStateAndGetOutputChannel(message, timeoutHelper);

                try
                {
                    outputChannel.Send(message, timeoutHelper.RemainingTime());
                    outputChannel.Close(timeoutHelper.RemainingTime());
                }
                finally
                {
                    outputChannel.Abort();
                }
            }
Esempio n. 3
0
        public override void Dispatch(MessageDelivery messageDelivery)
        {
            IOutputChannel channel = CreateChannelFactory().CreateChannel();
            bool           closed  = false;

            try
            {
                channel.Open();
                channel.Send(_converter.ToMessage(messageDelivery));
            }
            finally
            {
                channel.Close();
                closed = true;
            }
            if (!closed)
            {
                channel.Abort();
            }
        }
Esempio n. 4
0
 protected override void OnAbort()
 {
     _innerOutputChannel.Abort();
     base.OnAbort();
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            try
            {
                ParseArgs(args);
                Console.Title = "Message Sender";

                // Get credentials as Endpoint behavior
                TransportClientEndpointBehavior securityBehavior = new TransportClientEndpointBehavior();
                securityBehavior.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(serviceBusKeyName, serviceBusKey);

                // Create factory and channel using NetMessagingBinding
                NetMessagingBinding messagingBinding = new NetMessagingBinding("messagingBinding");
                EndpointAddress     address          = SampleManager.GetEndpointAddress(SampleManager.SessionlessQueueName, serviceBusNamespace);

                IChannelFactory <IOutputChannel> messagingChannelFactory = null;
                IOutputChannel messagingOutputChannel = null;
                try
                {
                    messagingChannelFactory = messagingBinding.BuildChannelFactory <IOutputChannel>(securityBehavior);
                    messagingChannelFactory.Open();
                    messagingOutputChannel = messagingChannelFactory.CreateChannel(address);
                    messagingOutputChannel.Open();

                    // Send messages to queue which does not require session
                    Console.WriteLine("Preparing to send messages to {0}...", SampleManager.SessionlessQueueName);
                    Thread.Sleep(3000);

                    SendMessages(messagingOutputChannel, messagingBinding);
                    messagingOutputChannel.Close();
                    messagingChannelFactory.Close();
                }
                catch (Exception)
                {
                    if (messagingOutputChannel != null)
                    {
                        messagingOutputChannel.Abort();
                    }
                    if (messagingChannelFactory != null)
                    {
                        messagingChannelFactory.Abort();
                    }
                    throw;
                }

                // Wait for all receivers to receive message
                Thread.Sleep(TimeSpan.FromSeconds(5.0d));
                Console.Clear();

                // Create factory and channel using custom binding
                CustomBinding customBinding = new CustomBinding("customBinding");
                address = SampleManager.GetEndpointAddress(SampleManager.SessionQueueName, serviceBusNamespace);

                IChannelFactory <IOutputChannel> customChannelFactory = null;
                IOutputChannel customOutputChannel = null;
                try
                {
                    customChannelFactory = customBinding.BuildChannelFactory <IOutputChannel>(securityBehavior);
                    customChannelFactory.Open();
                    customOutputChannel = customChannelFactory.CreateChannel(address);
                    customOutputChannel.Open();

                    // Send messages to queue which requires session
                    Console.Title = "Session MessageSender";
                    Console.WriteLine("Preparing to send messages to {0}...", SampleManager.SessionQueueName);
                    Thread.Sleep(3000);

                    SendMessages(customOutputChannel, customBinding);
                    customOutputChannel.Close();
                    customChannelFactory.Close();
                }
                catch (Exception)
                {
                    if (customOutputChannel != null)
                    {
                        customOutputChannel.Abort();
                    }
                    if (customChannelFactory != null)
                    {
                        customChannelFactory.Abort();
                    }
                    throw;
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception Occurred: {0}", exception);
                SampleManager.ExceptionOccurred = true;
            }

            // All messages sent
            Console.WriteLine("\nSender complete. Press [Enter] to exit.");
            Console.ReadLine();
        }
Esempio n. 6
0
 public void Abort()
 {
     _channel.Abort();
 }