Example #1
0
        private MessageBufferClient GetOrCreateQueue(TransportClientEndpointBehavior sharedSecredServiceBusCredential, Uri queueUri, ref MessageBufferPolicy queuePolicy)
        {
            MessageBufferClient client;

            try
            {
                client = MessageBufferClient.GetMessageBuffer(sharedSecredServiceBusCredential, queueUri);
                MessageBufferPolicy currentQueuePolicy = client.GetPolicy();
                queuePolicy = currentQueuePolicy;
                // Queue already exists.
                return(client);
            }
            //catch (EndpointNotFoundException)
            catch (FaultException)
            {
                // Exception when retrieving the current queue policy.
                // Queue Not found; absorb and make a new queue below.
                // Other exceptions get bubbled up.
            }
            catch (Exception)
            {
            }
            try
            {
                client = MessageBufferClient.CreateMessageBuffer(sharedSecredServiceBusCredential, queueUri, queuePolicy);
            }
            catch (Exception)
            {
                throw;
            }
            //Created new Queue.
            return(client);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the reliable Windows Azure Service Bus Message Buffer client connected to the specified message buffer
        /// located on the specified Service Bus endpoint and utilizing the specified custom retry policy.
        /// </summary>
        /// <param name="queueName">The name of the target message buffer (queue).</param>
        /// <param name="sbEndpointInfo">The endpoint details.</param>
        /// <param name="retryPolicy">The custom retry policy that will ensure reliable access to the underlying HTTP/REST-based infrastructure.</param>
        public ReliableServiceBusQueue(string queueName, ServiceBusEndpointInfo sbEndpointInfo, RetryPolicy retryPolicy)
        {
            Guard.ArgumentNotNullOrEmptyString(queueName, "queueName");
            Guard.ArgumentNotNull(sbEndpointInfo, "sbEndpointInfo");
            Guard.ArgumentNotNull(retryPolicy, "retryPolicy");

            this.sbEndpointInfo = sbEndpointInfo;
            this.retryPolicy    = retryPolicy;

            this.queuePolicy = new MessageBufferPolicy
            {
                ExpiresAfter    = TimeSpan.FromMinutes(120),
                MaxMessageCount = 100000,
                OverflowPolicy  = OverflowPolicy.RejectIncomingMessage
            };

            var address = ServiceBusEnvironment.CreateServiceUri(WellKnownProtocolScheme.SecureHttp, sbEndpointInfo.ServiceNamespace, String.Concat(sbEndpointInfo.ServicePath, !sbEndpointInfo.ServicePath.EndsWith("/") ? "/" : "", queueName));
            var credentialsBehaviour = new TransportClientEndpointBehavior();

            credentialsBehaviour.CredentialType = TransportClientCredentialType.SharedSecret;
            credentialsBehaviour.Credentials.SharedSecret.IssuerName   = sbEndpointInfo.IssuerName;
            credentialsBehaviour.Credentials.SharedSecret.IssuerSecret = sbEndpointInfo.IssuerSecret;

            MessageBufferClient msgBufferClient = null;

            this.retryPolicy.ExecuteAction(() =>
            {
                msgBufferClient = MessageBufferClient.CreateMessageBuffer(credentialsBehaviour, address, this.queuePolicy, DefaultQueueMessageVersion);
            });

            this.queueClient = msgBufferClient;
        }
Example #3
0
        private MessageBufferClient CreateMessageBuffer(string serviceNamespace, string messageBufferName, TransportClientEndpointBehavior behavior, MessageBufferPolicy policy)
        {
            MessageVersion messageVersion   = MessageVersion.Soap12WSAddressing10;
            Uri            messageBufferUri = GetMessageBufferUri();

            return(MessageBufferClient.CreateMessageBuffer(behavior, messageBufferUri, policy, messageVersion));
        }
        public static void PurgeBuffer(Uri bufferAddress, TransportClientEndpointBehavior credential)
        {
            Debug.Assert(BufferExists(bufferAddress, credential));

            MessageBufferClient client = MessageBufferClient.GetMessageBuffer(credential, bufferAddress);
            MessageBufferPolicy policy = client.GetPolicy();

            client.DeleteMessageBuffer();
            MessageBufferClient.CreateMessageBuffer(credential, bufferAddress, policy);
        }
Example #5
0
        void ApplyPolicy(MessageBufferPolicy policy)
        {
            try
            {
                Uri address = new Uri(RealAddress.AbsoluteUri.Replace(@"sb://", @"https://"));

                MessageBufferClient client = MessageBufferClient.GetMessageBuffer(Credential, address);
                client.DeleteMessageBuffer();
                MessageBufferClient.CreateMessageBuffer(Credential, address, policy);
                Explore();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Error applying change: " + exception.Message, "Service Bus Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        static void CreateBuffer(string bufferAddress, MessageBufferPolicy policy, TransportClientEndpointBehavior credential)
        {
            if (bufferAddress.EndsWith("/") == false)
            {
                bufferAddress += "/";
            }

            Uri address = new Uri(bufferAddress);

            if (BufferExists(address, credential))
            {
                MessageBufferClient client = MessageBufferClient.GetMessageBuffer(credential, address);
                client.DeleteMessageBuffer();
            }
            MessageBufferClient.CreateMessageBuffer(credential, address, policy);
        }
Example #7
0
        void OnCreate(object sender, EventArgs e)
        {
            Debug.Assert(m_AddressTextBox.Text != BaseAddress);

            MessageBufferPolicy policy = new MessageBufferPolicy();

            policy.Discoverability = DiscoverabilityPolicy.Public;

            if (m_CountTextBox.Text != "")
            {
                policy.MaxMessageCount = Convert.ToInt32(m_CountTextBox.Text);
            }

            if (m_ExpirationTime.Text != "")
            {
                policy.ExpiresAfter = TimeSpan.FromMinutes(Convert.ToInt32(m_ExpirationTime.Text));
            }

            switch (m_OverflowComboBox.Text)
            {
            case "Reject":
            {
                policy.OverflowPolicy = OverflowPolicy.RejectIncomingMessage;
                break;
            }

            default:
            {
                throw new InvalidOperationException("Unknown overflow value");
            }
            }
            if (m_AddressTextBox.Text.EndsWith(@"/") == false)
            {
                m_AddressTextBox.Text += @"/";
            }
            try
            {
                Client = MessageBufferClient.CreateMessageBuffer(Credential, new Uri(m_AddressTextBox.Text), policy);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Unable to create buffer: " + exception.Message, "Service Bus Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Close();
        }
Example #8
0
        private MessageBufferClient GetOrCreateQueue(TransportClientEndpointBehavior sharedSecredServiceBusCredential,
                                                     Uri queueUri, ref MessageBufferPolicy queuePolicy)
        {
            MessageBufferClient client;

            try
            {
                client      = MessageBufferClient.GetMessageBuffer(sharedSecredServiceBusCredential, queueUri);
                queuePolicy = client.GetPolicy();
                Console.WriteLine("Message buffer already exists at '{0}'.", client.MessageBufferUri);

                return(client);
            }
            catch (FaultException e)
            {
                // Not found. Ignore and make a new queue below.
                // Other exceptions get bubbled up.
            }

            client      = MessageBufferClient.CreateMessageBuffer(sharedSecredServiceBusCredential, queueUri, queuePolicy);
            queuePolicy = client.GetPolicy();
            Console.WriteLine("Message buffer created at '{0}'.", client.MessageBufferUri);
            return(client);
        }