public void PeekAndRetrieveMessage() { MessageBufferClient client = GetMessageBufferClient(); AddLog(String.Format("Message buffer '{0}'.", client.MessageBufferUri)); AddLog("Peek and Retrieve Message:" + PeekAndRetrieveMessage(client)); }
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)); }
private MessageBufferClient GetMessageBufferClient() { TransportClientEndpointBehavior behavior = GetACSSecurity(txtIssuerName.Text, txtIssuerKey.Text); Uri messageBufferUri = GetMessageBufferUri(); return(MessageBufferClient.GetMessageBuffer(behavior, messageBufferUri)); }
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); }
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); } }
/// <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; }
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); } } }
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; }
public void DeleteMessageBuffer() { MessageBufferClient client = GetMessageBufferClient(); // delete the message buffer client.DeleteMessageBuffer(); AddLog(String.Format("Message buffer {0} deleted.", client.MessageBufferUri)); }
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)); } }
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); }
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()); }
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); } }
//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); }
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; }
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()); }
MessageBufferPolicy GetBufferPolicy(string address) { if (address.StartsWith(@"sb://")) { return(null); } Uri bufferAddress = new Uri(address); MessageBufferClient client = MessageBufferClient.GetMessageBuffer(Credential, bufferAddress); return(client.GetPolicy()); }
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); } }
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."); } }
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); } }
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); }
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(); }
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(); } } }
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); }
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); } }
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); } } }
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(); } }
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); }