I have created a SB in the azure portal. By default the status is showing as Active. Let me have a scenario where i want to change the status of this SB, any idea on how to do that? Any pointers will be very helpful. We have 2 service bus and one needs to be active at a time. So how can we manage that?
By default the status is showing as Active. Let me have a scenario where i want to change the status of this SB, any idea on how to do that?
Service Bus works as a container or a namespace. The status of Azure Service Bus is internal used, we can't change it on Azure portal or using any API.
As #Sean Feldman said, we can only enable or disable the entities(queues or topics) in the Service Bus in the properties panel.
To disable all the queues and topics in a Service Bus, you could using following code.
string connectionString = "your connection string of service bus";
var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
IEnumerable<QueueDescription> queueList = namespaceManager.GetQueues();
foreach (QueueDescription qd in queueList)
{
qd.Status = EntityStatus.Disabled;
namespaceManager.UpdateQueue(qd);
}
IEnumerable<TopicDescription> topicList = namespaceManager.GetTopics();
foreach (TopicDescription td in topicList)
{
td.Status = EntityStatus.Disabled;
namespaceManager.UpdateTopic(td);
}
Related
I am trying the following code to check if the Azure Service Bus topic subscription already exists:
void Initialize()
{
CreateTopicSubscription().Wait();
//CreateTopicSubscription().GetAwaiter().GetResult();
}
async Task CreateTopicSubscription()
{
managementClient = new ManagementClient(serviceBusConnectionString);
if (!await managementClient.QueueExistsAsync(queueName).ConfigureAwait(false))
{ /* do some logic */ }
if (!await managementClient.SubscriptionExistsAsync(queueName, "subscriptionName1"))
{
await managementClient.CreateSubscriptionAsync(new SubscriptionDescription(queueName, "subscriptionName1"));
}
}
And I get the following error on the line with SubscriptionExistsAsync:
Microsoft.Azure.ServiceBus.ServiceBusException: 'The specified HTTP
verb (GET) is not valid. To know more visit
https://aka.ms/sbResourceMgrExceptions. .
TrackingId:aa8b87cc-ea45-4fdc-be39-bf1877774b0e_G24,
SystemTracker:needspacetests:Queue:sc-messenger,
Timestamp:2019-12-18T11:33:45'
What am I doing wrong/missing here?
NOTES:
I use a newly created Azure Service Bus in Basic Plan and newly (manually) created Queue.
queueName has the value of an existing Queue.
I use a newly created Azure Service Bus in Basic Plan
The basic tier doesn't have topics and subscriptions. You should switch to the Standard tier if you need to use topics and subscriptions.
I am using Microservices deployed on Kubernetes built using asp.net core 2.2. Each microservice is subscribed to different azure service bus "Subscription". In application start up the service add subscription rules (filters) for events that it want to listen to.
Everything works fine and service process messages that it's subscribed to except when i kill the pod and Kubernetes bring back the replica and then service stops processing the messages and they keep on stacking in the queue. Regardless of how much i wait they are not processed even when i restart the pod.
My Startup.cs
public static IServiceCollection RegisterEventBus(this IServiceCollection services, IConfiguration configuration)
{
var subscriptionClientName = configuration["SubscriptionClientName"];
services.AddSingleton<IEventBus, EventBusServiceBus>(sp =>
{
var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>();
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>();
var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>();
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>();
return new EventBusServiceBus(serviceBusPersisterConnection, logger,
eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope);
});
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddTransient<PaymentProcessedIntegrationEventHandler>();
services.AddTransient<OrderStatusChangedIntegrationEventHandler>();
return services;
}
//Subscribe to Events
private void ConfigureEventBus(IApplicationBuilder app)
{
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
eventBus.Subscribe<PaymentProcessedIntegrationEvent, PaymentProcessedIntegrationEventHandler>();
eventBus.Subscribe<OrderStatusChangedIntegrationEvent, OrderStatusChangedIntegrationEventHandler>();
}
I copied official Azure Service bus class from eshopcontainers from github and using it in my project here.
https://github.com/ImranMA/MicroCouriers/blob/master/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs
Any help is highly appreciated !
For a test I created a free tier IoT Hub and basic service bus. But when I click on the "+ Queue" and fill out all the fields; setting name, size (1gb), message to to live (14 days, default), lock duration (30 seconds, default) and only "Enable partitioning" I get this errormessage when I click create:
The property 'AutoDeleteOnIdle' cannot be set when creating a Queue because the namespace 'x' is using 'Basic' tier.
I should be able to create queues, but not topics with this setup. Are one of the properties of the "Create queue" blade running with a different naming convention from "AutoDeleteOnIdle"?
The property 'AutoDeleteOnIdle' cannot be set when creating a Queue because the namespace 'x' is using 'Basic' tier.
I could reproduce the issue with the following sample when I am using 'Basic' tier.
var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
namespaceManager.CreateQueue(new QueueDescription("testqueue") {
DefaultMessageTimeToLive = TimeSpan.FromDays(14),
LockDuration = TimeSpan.FromSeconds(30),
EnablePartitioning = true,
AutoDeleteOnIdle = TimeSpan.FromMinutes(5) });
}
Exception
After I scale it to standard tier, the above code works fine. If possible, please try to scale to standard tier and check if you could create queue&specify the property AutoDeleteOnIdle.
In my case, I've initially created a service bus with basic. Later I realized that topic is not supported in basic. So, I've deleted the service bus component and recreated a new service bus component with Standard using the same name that I've used before. But, I got above error "SubCode=40000. The property 'AutoDeleteOnIdle' cannot be set when creating a Queue because the namespace 'dev-sb-xxx' is using 'Basic' tier.."
It seems to be a bug to me with azure portal. When I checked scale, it is still shown as basic. I've changed it to Standard and it worked fine.
Is there an easy way to send an alert or notification in the Azure Management portal if a worker role throws an exception or has an error?
I am using Azure 2.5
I have tracing and diagnostics all set up and can view the logs in the server explorer of Visual studio, but is there anyway to set an alert if for example and error message appears in the logs.
I know you can set up alerts for monitoring metrics in the Management portal is there an easy way to add metrics for errors and exceptions?
Or someway to get C# exception code to create notifications or alerts in the Azure Management portal?
I ended up using email alerts and Application insights to monitor my worker role in the Azure portal. I created an Application insight on the portal according to these instructions.
Using the Nuget package manager in Visual Studio I added the Application insights API, Application insights for website (even though my worker role is not a web app) and the Application insights trace listener.
I then created an Application insight instance by adding the following to the worker role.
private TelemetryClient tc = new TelemetryClient();
And then adding this to the onStart method.
tc.Context.InstrumentationKey = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX";
You can find your insturmentation Key in the Azure Portal.
After running, or deploying my worker role I could then view all of my Trace.TraceInformation and TraceError statements in the Azure portal as well as add tc.TrackError and tc.TrackEvent statements to track errors and events.
TrackError worked perfectly for notifying me when an exception was thrown.
I use SendGrid for sending emails through Azure because it's free. Here is what I would do something like below:
try
{
//....
}
catch(Exception ex)
{
MailMessage mailMsg = new MailMessage() {
//Set your properties here
};
// Add the alternate body to the message.
mailMsg.AlternateViews.Add(
AlternateView.CreateAlternateViewFromString(Body
, new System.Net.Mime.ContentType("text/html")));
SmtpClient smtpClient = new SmtpClient(
ServerGlobalVariables.SmtpServerHost
, Convert.ToInt32(587));
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(
ServerGlobalVariables.SmtpServerUserName
, ServerGlobalVariables.SmtpServerPassword);
smtpClient.Credentials = credentials;
smtpClient.Send(mailMsg);
}
Please note that I store my credits in a globalvariables class called ServerGlobalVariables. Also, I send my emails formatted as HTML, but you don't have to do that.
We are facing problem in CRM 2013-Azure Integration.
Below lines explains the CRM 2013 –Azure integration.
1.Plugin will read the data from CRM record and send the data to Azure Service Bus Queue.
2.Azure worker role will read the data from service bus queue and send it to WCF service which will insert/update the data in Azure DB.
When we call the send method to send the data to service bus queue we are getting “channel open did not complete within the specified timeout” error. Below is the code snippet of Azure Service Bus call.
Uri runtimeUri = ServiceBusEnvironment.CreateServiceUri(ConfigurationManager.AppSettings["schemaName"], ConfigurationManager.AppSettings["serviceNamespace"], string.Empty);
MessagingFactory mf = MessagingFactory.Create(runtimeUri,TokenProvider.CreateSharedAccessSignatureTokenProvider(ConfigurationManager.AppSettings["keyName"], ConfigurationManager.AppSettings["sharedAccessKey"]));
sendClient = mf.CreateQueueClient(ConfigurationManager.AppSettings["queuePath"]);
BrokeredMessage helloMessage = new BrokeredMessage(list of CRM data));
helloMessage.MessageId = Guid.NewGuid().ToString();
sendClient.Send(helloMessage);
But when we do the same operation from local(Outside CRM) it is working fine. Please suggest us some solution if you have any.