Example #1
0
        public void PeekAndRetrieveMessage()
        {
            MessageBufferClient client = GetMessageBufferClient();

            AddLog(String.Format("Message buffer '{0}'.", client.MessageBufferUri));
            AddLog("Peek and Retrieve Message:" + PeekAndRetrieveMessage(client));
        }
Example #2
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));
        }
Example #3
0
        private MessageBufferClient GetMessageBufferClient()
        {
            TransportClientEndpointBehavior behavior = GetACSSecurity(txtIssuerName.Text, txtIssuerKey.Text);
            Uri messageBufferUri = GetMessageBufferUri();

            return(MessageBufferClient.GetMessageBuffer(behavior, messageBufferUri));
        }
Example #4
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 #5
0
        void DeleteBuffers(ServiceBusTreeNode treeNode)
        {
            if (treeNode.ServiceBusNode != null)
            {
                if (treeNode.ServiceBusNode.Policy != null)
                {
                    if (treeNode.ServiceBusNode.Policy is MessageBufferPolicy)
                    {
                        string nodeAddress = treeNode.ServiceBusNode.Address;
                        nodeAddress = nodeAddress.Replace(@"sb://", @"https://");

                        TransportClientEndpointBehavior credential = Graphs[ServiceNamespace.ToLower()].Credential;
                        Uri address = new Uri(nodeAddress);
                        try
                        {
                            MessageBufferClient.GetMessageBuffer(credential, address).DeleteMessageBuffer();
                        }
                        catch
                        {}
                    }
                }
            }
            foreach (TreeNode node in treeNode.Nodes)
            {
                DeleteBuffers(node as ServiceBusTreeNode);
            }
        }
Example #6
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 #7
0
        void Dequeue(object arg)
        {
            Uri bufferAddress = arg as Uri;

            Debug.Assert(bufferAddress != null);

            MessageBufferClient bufferClient = MessageBufferClient.GetMessageBuffer(m_Credential, bufferAddress);

            while (true)
            {
                Message message = null;

                try
                {
                    message = bufferClient.Retrieve();
                }
                catch (TimeoutException)
                {
                    Trace.WriteLine("Timed out before retirieving message");
                    continue;
                }
                if (message.Headers.Action == CloseAction)
                {
                    return;
                }
                else
                {
                    Dispatch(message);
                }
            }
        }
Example #8
0
        void OnDragDrop(object sender, DragEventArgs args)
        {
            Cursor.Current = Cursors.Default;
            Debug.Assert(m_DraggedNode != null);

            ServiceBusTreeNode targetNode = GetTargetNode(args);

            if (targetNode.ServiceBusNode == null)
            {
                return;
            }
            if (targetNode.ServiceBusNode.Policy != null)//A router or a buffer
            {
                if (targetNode.ServiceBusNode.Policy is RouterPolicy)
                {
                    Trace.WriteLine("Droped at: " + targetNode.Text);
                    string draggedAddress = m_DraggedNode.ServiceBusNode.Address;
                    draggedAddress = draggedAddress.Replace(@"https://", @"sb://");
                    draggedAddress = draggedAddress.Replace(@"http://", @"sb://");

                    string targetAddress = targetNode.ServiceBusNode.Address;
                    targetAddress = targetAddress.Replace(@"https://", @"sb://");
                    targetAddress = targetAddress.Replace(@"http://", @"sb://");

                    TransportClientEndpointBehavior credential = Graphs[ServiceNamespace.ToLower()].Credential;

                    Uri draggedUri = new Uri(draggedAddress);
                    Uri targetUri  = new Uri(targetAddress);

                    try
                    {
                        RouterClient targetClient = RouterManagementClient.GetRouter(credential, targetUri);
                        if (m_DraggedNode.ServiceBusNode.Policy is RouterPolicy)
                        {
                            RouterClient draggedClient = RouterManagementClient.GetRouter(credential, draggedUri);

                            draggedClient.SubscribeToRouter(targetClient, TimeSpan.MaxValue);
                        }
                        else
                        {
                            MessageBufferClient draggedClient = MessageBufferClient.GetMessageBuffer(credential, draggedUri);

                            /* TODO Restore on next release
                             * draggedClient.SubscribeToRouter(targetClient,TimeSpan.MaxValue);
                             */
                        }
                        OnExplore(this, EventArgs.Empty);

                        m_ServiceBusTree.SelectedNode = targetNode;
                        m_ServiceBusTree.Select();
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show("Unable to subscribe: " + exception.Message, "Service Bus Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            m_DraggedNode = null;
        }
Example #9
0
        public void DeleteMessageBuffer()
        {
            MessageBufferClient client = GetMessageBufferClient();

            // delete the message buffer
            client.DeleteMessageBuffer();
            AddLog(String.Format("Message buffer {0} deleted.", client.MessageBufferUri));
        }
Example #10
0
 private static void MakeMove(MessageBufferClient bufferClient, String move)
 {
     Console.WriteLine("{0} -> {1}", bufferClient.MessageBufferUri.LocalPath[1], move);
     using (Message moveMessage = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "urn:Message", move))
     {
         bufferClient.Send(moveMessage, TimeSpan.FromSeconds(1d));
     }
 }
Example #11
0
        public void CreateMessageBuffer()
        {
            Console.Write("Press [Enter] to create the message buffer: ");
            Console.ReadLine();

            // Create the client for the message buffer.
            this.client = GetOrCreateQueue(this.credential, this.uri, ref this.policy);
        }
Example #12
0
        public new T CreateChannel()
        {
            Debug.Assert(Endpoint.Binding is NetOnewayRelayBinding);
            ServiceBusHelper.VerifyBuffer(Endpoint.Address.Uri.AbsoluteUri, ServiceBusCredentials);

            m_BufferClient = MessageBufferClient.GetMessageBuffer(ServiceBusCredentials, Endpoint.Address.Uri);

            return(base.CreateChannel());
        }
Example #13
0
 void SendCloseMessages()
 {
     foreach (Uri bufferAddress in m_BufferAddresses)
     {
         MessageBufferClient bufferClient = MessageBufferClient.GetMessageBuffer(m_Credential, bufferAddress);
         Message             message      = Message.CreateMessage(MessageVersion.Default, CloseAction);
         bufferClient.Send(message);
     }
 }
Example #14
0
        //End - Needed for tokenmode

        public MessageBufferClient GetMessageBufferClient()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            TransportClientEndpointBehavior behavior = new TransportClientEndpointBehavior();

            if (isTokenMode)
            {
                behavior.CredentialType                        = TransportClientCredentialType.Saml;
                behavior.Credentials.Saml.SamlToken            = GetTokenString(organizationName, true);
                behavior.Credentials.SharedSecret.IssuerSecret = solutionPassword;
            }
            else
            {
                behavior.CredentialType = TransportClientCredentialType.SharedSecret;
                behavior.Credentials.SharedSecret.IssuerName   = DefaultIssuer;
                behavior.Credentials.SharedSecret.IssuerSecret = solutionPassword;
            }

            #region scheme
            string scheme = Uri.UriSchemeHttp;
            if (securityMode == "Transport")
            {
                scheme = Uri.UriSchemeHttps;
            }
            #endregion
            #region Queue contract.

            Uri queueAddress = ServiceBusEnvironment.CreateServiceUri(scheme, solutionName, path);

            // create a new queue policy with an expiration of 1 hour
            MessageBufferPolicy queuePolicy = new MessageBufferPolicy();
            queuePolicy.ExpiresAfter = TimeSpan.FromHours(1);
            if (securityMode != "Transport")             //That is securityMode == None.
            {
                queuePolicy.TransportProtection = TransportProtectionPolicy.None;
            }

            MessageBufferClient messageBufferClient = null;
            for (; ;)
            {
                try
                {
                    // get the existing queue or create a new queue if it doesn't exist.
                    messageBufferClient = GetOrCreateQueue(behavior, queueAddress, ref queuePolicy);
                }
                catch
                {
                    continue;
                }
                break;
            }
            return(messageBufferClient);

            #endregion
        }
        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 #16
0
 private static String GetMove(MessageBufferClient bufferClient)
 {
     String move;
     using (Message moveMessage = bufferClient.Retrieve())
     {
         move = moveMessage.GetBody<String>();
     }
     Console.WriteLine("{0} <- {1}", bufferClient.MessageBufferUri.LocalPath[1], move);
     return move;
 }
Example #17
0
        protected override T CreateChannel()
        {
            Debug.Assert(Endpoint.Binding is NetOnewayRelayBinding);

            m_BufferAddress = new Uri("https://" + Endpoint.Address.Uri.Host + Endpoint.Address.Uri.LocalPath);
            ServiceBusHelper.VerifyBuffer(m_BufferAddress.AbsoluteUri, Credential);

            m_BufferClient = MessageBufferClient.GetMessageBuffer(Credential, m_BufferAddress);

            return(base.CreateChannel());
        }
Example #18
0
        MessageBufferPolicy GetBufferPolicy(string address)
        {
            if (address.StartsWith(@"sb://"))
            {
                return(null);
            }

            Uri bufferAddress = new Uri(address);

            MessageBufferClient client = MessageBufferClient.GetMessageBuffer(Credential, bufferAddress);

            return(client.GetPolicy());
        }
Example #19
0
 private void btnCreateBuffer_Click(object sender, EventArgs e)
 {
     try
     {
         TransportClientEndpointBehavior behavior = GetACSSecurity(txtIssuerName.Text, txtIssuerKey.Text);
         MessageBufferPolicy             policy   = GetMessagBufferPolicy(10d, 100);
         //  messageBufferUri = ServiceBusEnvironment.CreateServiceUri("http", txtServiceNamespace.Text, txtMessageBuffer.Text);
         MessageBufferClient client = CreateMessageBuffer(txtServiceNamespace.Text, txtMessageBuffer.Text, behavior, policy);
         AddLog(String.Format("Message Buffer {0} created", client.MessageBufferUri.ToString()));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
     }
 }
Example #20
0
        public void SendMessages()
        {
            MessageBufferClient client = GetMessageBufferClient();

            AddLog(String.Format("Message buffer '{0}'.", client.MessageBufferUri));


            // send three messages to the message buffer
            for (int i = 1; i <= 10; ++i)
            {
                string msg = String.Format("{0}-{1}", txtMessage.Text, System.Guid.NewGuid().ToString("N"));
                SendMessage(msg, client);
                AddLog(msg + " sent.");
            }
        }
Example #21
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);
            }
        }
Example #22
0
 private string PeekAndRetrieveMessage(MessageBufferClient client)
 {
     System.ServiceModel.Channels.Message lockedMessage = client.PeekLock();
     try
     {
         client.DeleteLockedMessage(lockedMessage);
         return(lockedMessage.GetBody <string>());
     }
     finally
     {
         if (lockedMessage != null)
         {
             lockedMessage.Close();
         }
     }
 }
        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 #24
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 #25
0
        private string RetrieveMessage(MessageBufferClient client)
        {
            System.ServiceModel.Channels.Message retrievedMessage = null;;

            try
            {
                retrievedMessage = client.Retrieve();

                return(retrievedMessage.GetBody <string>());
            }
            finally
            {
                if (retrievedMessage != null)
                {
                    retrievedMessage.Close();
                }
            }
        }
Example #26
0
        public static void DeleteBuffer(string bufferAddress, string secret)
        {
            if (bufferAddress.EndsWith("/") == false)
            {
                bufferAddress += "/";
            }

            Uri address = new Uri(bufferAddress);

            TransportClientEndpointBehavior credential = new TransportClientEndpointBehavior();

            credential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(DefaultIssuer, secret);

            if (BufferExists(address, credential))
            {
                MessageBufferClient client = MessageBufferClient.GetMessageBuffer(credential, address);
                client.DeleteMessageBuffer();
            }
        }
        internal static bool BufferExists(Uri bufferAddress, TransportClientEndpointBehavior credential)
        {
            try
            {
                MessageBufferClient client = MessageBufferClient.GetMessageBuffer(credential, bufferAddress);
                MessageBufferPolicy policy = client.GetPolicy();
                if (policy.TransportProtection != TransportProtectionPolicy.AllPaths)
                {
                    throw new InvalidOperationException("Buffer must be configured for transport protection");
                }
                return(true);
            }
            catch (FaultException exception)
            {
                Debug.Assert(exception.Message == "Policy could not be retrieved: ContentType is incorrect");
            }

            return(false);
        }
Example #28
0
        void OnDelete(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete the buffer?", "Service Bus Explorer", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

            if (result == DialogResult.No)
            {
                return;
            }
            try
            {
                Uri address = new Uri(RealAddress.AbsoluteUri.Replace(@"sb://", @"https://"));
                MessageBufferClient client = MessageBufferClient.GetMessageBuffer(Credential, address);
                client.DeleteMessageBuffer();
                Explore();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Error deleting buffer: " + exception.Message, "Service Bus Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #29
0
        void Dequeue(object arg)
        {
            Uri bufferAddress = arg as Uri;

            Debug.Assert(bufferAddress != null);

            MessageBufferClient bufferClient = MessageBufferClient.GetMessageBuffer(m_Credential, bufferAddress);

            while (true)
            {
                Message message = bufferClient.Retrieve();
                if (message.Headers.Action == CloseAction)
                {
                    return;
                }
                else
                {
                    Dispatch(message);
                }
            }
        }
Example #30
0
        void OnPurge(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to remove all messages?", "Service Bus Explorer", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

            if (result == DialogResult.No)
            {
                return;
            }
            try
            {
                Uri address = new Uri(RealAddress.AbsoluteUri.Replace(@"sb://", @"https://"));

                MessageBufferClient client = MessageBufferClient.GetMessageBuffer(Credential, address);
                MessageBufferPolicy policy = client.GetPolicy();
                ApplyPolicy(policy);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Error purging buffer: " + exception.Message, "Service Bus Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public static void DeleteBuffer(string bufferAddress, string secret)
        {
            if (bufferAddress.EndsWith("/") == false)
            {
                bufferAddress += "/";
            }

            Uri address = new Uri(bufferAddress);

            TransportClientEndpointBehavior credential = new TransportClientEndpointBehavior();

            credential.CredentialType = TransportClientCredentialType.SharedSecret;
            credential.Credentials.SharedSecret.IssuerName   = DefaultIssuer;
            credential.Credentials.SharedSecret.IssuerSecret = secret;

            if (BufferExists(address, credential))
            {
                MessageBufferClient client = MessageBufferClient.GetMessageBuffer(credential, address);
                client.DeleteMessageBuffer();
            }
        }
Example #32
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);
        }