Azure pub-sub for arm deployment state change - c#

I have the following requirement: I'm deploying an ARM template from a service fabric service. Now I want to subscribe to that deployment resource and react/write a handler/custom webhook when it's state changes to a terminal state (success or failure). Currently we're polling every 60 seconds to check the status. I am reading about event hubs and event grids, but haven't yet found any helpful links.

Related

Azure Function with ServiceBusTrigger not firing when scheduled

I have an Azure Function (~4) running in a Linux Consumption plan. It targets .Net 6. It uses a ServiceBusTrigger. The ServiceBus has two queues, qprocessing and qcomplete. The first queue, qprocessing, has several messages, which are scheduled for delivery to this function. The ServiceBusTrigger is not firing and the messages stay on the queue until I investigate why they didn't execute.
I use the explorer to peek at the messages. Then they fire. When the function executes the message is moved to the queue, qcomplete. The following examples show what I received in the complete queue.
"DeliveryDateTime":"2022-01-15T12:00:00","SendRequested":"2022-01-16T10:12:40.3301147Z"
"DeliveryDateTime":"2022-01-15T12:00:00","SendRequested":"2022-01-16T10:12:40.3285614Z"
DeliveryDateTime is EST. SendRequested is UTC as set by the function when it executes. These messages remained on the queue for 17 hours. And they didn't fire until I used the explorer to peek at them.
I've been noticing this issue of unreliable delivery when scheduling a message to be enqueued.
I have Application Insights enabled, and I see no errors or exceptions when I execute the following traces for the last three days.
traces
| where message contains '"state": "Error"'
traces
| where message contains "Exception while executing function"
The function executes, but I have to peek at the ServiceBus queue first.
Or I have to access the Azure function app's web site. Just showing the Azure function app's web site generates a result.
For now, I have a monitor running every 15 minutes, which accesses the function app's web site. It's the page that says, "Your Functions 4.0 App is up and running."
UPDATED
The problem is in the Scale Controller not becoming aware of your trigger or having problems with it.
Add the SCALE_CONTROLLER_LOGGING_ENABLED setting to your configuration as per this doc: Configure scale controller logs
This will add in the traces table logging about the Scale Controller and you might see something like this
"Function app does not contain any active triggers", which indicates that when your app will go idle, the Scale Controller will not wake it up, not being aware of any trigger.
After the function is deployed there must be a sync of triggers sometimes is automatic, sometimes is manual, sometimes it fails.
In my case altering the host.json file was the issue (like this) and also "leftovers" from previous deploys inside the storage account used by the function, both in the Blobs and in the File Shares that gave different kind of problems but still they invalidated my trigger
In other cases is a mixture of deployment method not triggering stuff, by design or by failure.

Azure Service Bus Connections

I have inherited an azure service bus solution - C#, Web Api with Singleton service implementing the queue. Running locally on my PC, I can publish a message to my Dev queue and see that event consumed by my service bus receiver. No problem.
In our staging environment however my receiver is not firing so my code never processes the messages. I found an instance where a different environment was pointing to the staging queue purely by luck which makes me think "what else is using this queue". We have no application logging (useless I know) of when events are published or consumed so I wondered, is there a way from within Azure to see either
What is consuming the events published to the queue, or
What is currently connected to the queue so I can validate each connection and make sure a dev in a far flung office isn't running test programs using the queue.
Thanks
Create application insights instance
Connect your web app in azure to the created AI
after some time you will be able to see requests to other systems sent by your app (in application map you'll see fancy diagram of requests, in logs you can query requests to service bus)
Drop the AI instance if you don't need it anymore

How to enable reminders from an Azure based MVC application?

When a manager creates a task and sets the activation date in the future, it's supposed to be stored in the DB. No message is being dispatched out to the regarded workers, until a day or two before it's due. When the time's approaching, an email's being sent out to the subordinates.
Previously I've resolved that using a locally run Windows Service that scheduled the messaging. However, as I'm implementing something similar in the Azure, I'm not sure how to resolve it (other than actually hosting my own Windows Server in the cloud, of course, but kind of defeats the whole point).
Since my MVC application is strictly event driven, I've browsed around in the Azure portal to find a utility to schedule or postpone a method being invoked. No luck. So at the moment, all the emails are dispensed immediately and the scheduling is performed by keeping the message in the inbox until it's time (or manually setting up an appointment).
How should I approach the issue?
Other possible solution is to use Queueing mechanism. You can use Azure Storage Queues or Service Bus Queues.
The way it would work is when a task is created and saved in the database, you will write a message in a queue. This message will contain details about the task (may be a task id). However that message will be invisible by default and will only become visible after certain amount of time (you will calculate this period based on when you would need to send out the email). When the visibility timeout period expires, the message will become available to be consumed in the queue. Then you will have a WebJob with a Queue trigger (i.e. the WebJob will become alive when there's a message in the queue). In your WebJob code, you will fetch the task information from the database and send the notification to concerned person.
If you're using Azure Storage Queue, the property you would be interested in is InitialVisibilityTimeout. Please see this thread for more details: Azure storage queue message (show at specific time).
If you're using Azure Service Bus Queue, the property you would be interested in is BrokeredMessage.ScheduledEnqueueTimeUtc. You can read more about this property here: https://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.brokeredmessage.scheduledenqueuetimeutc.aspx.
One solution to run background tasks is to use Web Jobs. Web Jobs can run on a schedule (let's say once per day), manually or triggered by a message in a queue.
You can use Azure WebJobs. Basically, create a WebJob and schedule it to regularly check the data in your database for upcoming tasks and then notify people.

How to keep track of the services registered in SOA service registry & discovery

I have been working on the SOA POC since last few days. For service discovery & registry, we are considering Consul. Once we have registered the services in consul, how we should keep track of running status of the registered services?
We are implementing things on .net platform where some wcf services are hosted on the different appdomains, some in separate console process. We can keep track of the services in two ways.
Listening the ports using socket connection with heartbeats .
Handling the appdomain unload & console exit events.
A. Is there any other way to handle this scenario?
B. How we can get notification when console application process gets terminated ? procss might be killed,closed etc. How we can gracefully remove the service registry entry from Consul central repository?
C. Listening all the ports with certain heartbeat is efficient way as it will keep threads busy all the times?
Any help is most appreciated?
A. You can monitor the health of your services using any of the
checks defined here
B. To gracefully remove a service from consul, you can do this http
call to the local consul agent. I suggest adding this to the
closing logic of your service. If you want consul to give you some sort of warning when your sevice goes down, you can use Watches
C. Health checks are performed on a set interval. So you decide the
intensity of the checks. For example: every 30 seconds

How to update my desktop application from a Windows Phone 7.5 Mobile application

Our desktop application require to be updated directly when a mobile employee sends any message from his/her windows phone 7 mobile.
Currently our requirement is that send a message from our desktop application to a Windows Phone 7.5 which we are able to achive easily using PUSH Notifications, Now when the user takes some action against the sent message the windows phone app calls the WCF service and pass the message to that WCF which receives the message and puts into the database and application reads it later and this is where problem lies. Because our WCF is putting that message into database our application is polling it every 5 second and if any replies received from any of our drivers then it is updating the UI.
What we want to achieve is when we receive any reply our desktop applicaton should be notified automatically and udpates the UI and then put it into the database.
So please share your experience on this issue.
Thanks
Why not update the WCF service to notify any registered "listeners" (i.e. running instances of your client app) that the database has been updated with new information?
You could do this by having your service expose a service that can be called by clients wanting to register for some/all event types. The client app(s) host a service implementing a callback contract that the service can call when the registered events are raised.
There's a good MSDN article one-way, callback and pub-sub messaging with WCF: http://msdn.microsoft.com/en-us/magazine/cc163537.aspx.
Be sure to keep track of and throttle how many events your client app is receiving per second - the last thing you want to have happen is for 100 client apps to all hit the server 50 times each if 50 events are raised sumultaneously!
Richard's solution is probably more proper, since it describes using nicely packaged WCF APIs that will do a lot for you. Another way could be to implement long-polling yourself. You could then also update your Windows Phone clients when they need to receive an immediate update. I wrote an article on that some time ago which you can find if you google long polling on Windows Phone.

Categories