Trying to get Azure Webjobs to react to incoming Service Bus event, Im running this by hitting F5. Im getting the error at startup.
No job functions found. Try making your job classes and methods
public. If you're using binding extensions (e.g. ServiceBus, Timers,
etc.) make sure you've called the registration method for the
extension(s) in your startup code (e.g. config.UseServiceBus(),
config.UseTimers(), etc.).
My functions-class look like this:
public class Functions
{
// This function will get triggered/executed when a new message is written
// on an Azure Queue called queue.
public static void ProcessQueueMessage([ServiceBusTrigger("test-from-dynamics-queue")] BrokeredMessage message, TextWriter log)
{
log.WriteLine(message);
}
}
I have every class and method set to public
I am calling config.UseServiceBus(); in my program.cs file
Im using Microsoft.Azure.WebJobs v 1.1.2
((Im not entirely sure I have written the correct AzureWebJobsDashboard- and AzureWebJobsStorage-connectionstrings, I took them from my only Azure storage-settings in Azure portal. If that might be the problem, where should I get them ))
According to your mentioned error, it seems that you miss parameter config for ininitializing JobHost. If it is that case, please use the following code.
JobHost host = new JobHost(config)
More detail info about how to use Azure Service Bus with the WebJobs SDK please refer to the document.The following is the sample code from document.
public class Program
{
public static void Main()
{
JobHostConfiguration config = new JobHostConfiguration();
config.UseServiceBus();
JobHost host = new JobHost(config);
host.RunAndBlock();
}
}
Related
I am trying to find a way to run some code one time (where I set connection strings, DI, and other configs) when my Azure function starts. So right now, it calls a Run method as the entrypoint with this in the generated function.json:
"entryPoint": "MyFunctionApp.MessageReceiver.Run"
This Run method uses an EventHubTrigger and processes incoming messages like so:
[FunctionName("MessageReceiver")]
public static void Run([EventHubTrigger("eventHubName", Connection = "eventHubConnection")]string message, TraceWriter log)
{
if (string.IsNullOrWhiteSpace(message))
{
log.Info($"C# Event Hub trigger function processed a message: {message}");
}
}
Is there a way that I can run some code on the initial startup before this Run method is called? Or is there a way to declare an entrypoint that I can call before this class and then call Run() and somehow pass in the trigger? I am trying to find a way that avoids hackish stuff like setting boolean properties to see if the app has started.
You can implement an IExtensionConfigProvider. Those will be scanned and execute on "Startup".
using Microsoft.Azure.WebJobs.Host.Config;
namespace MyFunctionApp
{
public class Startup : IExtensionConfigProvider
{
public void Initialize(ExtensionConfigContext context)
{
// Put your intialization code here.
}
}
}
At the 2019 Build conference, Microsoft released the functionality to have a callable method when the Azure Function app starts up. This can be used for registering DI classes, creating static DB connections, etc.
The documentation for these new features can be found at Azure Function Dependency Injection
I wanted to create a console app as a WebJob using .NET Core but the WebJobs SDK is not yet available in .NET Core.
I've been advised to handle the scenario of reading messages from Azure Storage Queue manually. Looks like all the WebJobs SDK does is to keep polling the queue anyway.
Is the following code the basic idea in doing this? It doesn't look very sophisticated but not sure how it can be more sophisticated.
static void Main(string[] args)
{
var runContinuously = true;
while (runContinuously)
{
ReadAndProcessMessage();
System.Threading.Thread.Sleep(1000);
};
}
private static void ReadAndProcessMessage()
{
// Read message
ReadMessage();
// Process message and handle the work
HandleWork();
}
That will work. And I like simplicity.
The QueueTriggerAttribute makes use of a random exponential back-off algorithm to help minimize your transaction costs. If you'd like to trace through the logic of how this is accomplished, starting with the QueueListener class is a good way to go. Clone the project and then hop over to the RandomizedExponentialBackoffStrategy class.
My Azure WebJob used to run in the VS2015 Debugger, but I found it gradually became very intermittent and now won't run at all. It works fine it I deploy it to Azure. The job is marked as RunOnStartUp.
public class Program
{
static void Main()
{
var config = new JobHostConfiguration();
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();
}
}
public class TestJob : BaseJob
{
public static async Task StartupJob([TimerTrigger("05:00:00", RunOnStartup = true)] TimerInfo timerInfo, TextWriter log)
{
log.WriteLine("StartupJob");
await Jobs.Test(some params);
log.WriteLine("Sorted");
}
}
What do I need to do to get it running in the Debugger?
I'm guessing you use the same storage account for your job in Azure and when you debug it locally? If that's the case - the TimeTrigger runs as a singleton which means it needs to acquire a lock to be able to execute. If your webjob is already running in Azure your local version, which you're trying to debug, is not able to acquire the lock.
To avoid this just use different storage accounts for "live" Azure version and local local development.
I would also recommend to enable "development settings" - config.UseDevelopmentSettings(); - when you debug locally. If you enable it you'll see the messages "unable to acquire lock for function..." (or something similar).
See Jason Haley's comment in this thread:
(total hack but should work) rename the function while debugging so
the lock listener blob name will be different.
This hack worked for me. Maybe to make it less hacky, you could use the Disable-attribute to create a timer-triggered function that would only be enabled in your local environment:
Create "MyFunction", which handles the logic. This is the one that will run in your Azure app. Note RunOnStartup=false as recommended by the docs.
[FunctionName("MyFunction")]
public async Task RunJob(
[TimerTrigger("0 0 0 * * *", RunOnStartup = false)] TimerInfo timer)
{
//logic here
}
Create "MyFunction-Local" with the Disable attribute and a different method name. All this does is call the method above.
[FunctionName("MyFunction-Local")]
[Disable("Disable_MyFunction")]
public async Task RunJobLocal(
[TimerTrigger("0 0 0 * * *", RunOnStartup = true)] TimerInfo timer)
{
RunJob(timer);
}
In your local app configuration, set {"Disable_MyFunction" = false}, whereas for the app running in Azure, set this to true.
Am trying to implement SLAB for my Azure Web app (In Process) and my listner is Azure table Storage (table conection string) ,
the problem am facing is -“EventSource.IsEnabled() = always returns false”
(Am running the application from VS2013 with IIS express)
my code
————global.asax
var listener2 = new ObservableEventListener();
listener2.EnableEvents(SBEvents.Log, EventLevel.Verbose,Keywords.All);
listener2.LogToWindowsAzureTable(“sdf”, “DefaultEndpointsProtocol=https;AccountName=********;AccountKey=****************);
———-Event Source
Public class SBEvents :EventSource {
public class keywords{...}
public class Tasks {..}
private static readonly Lazy Instance = new Lazy(() => new SBEvents());
public static SBEvents Log { get { return Instance.Value; } }
[Event(102, Message = “Bike started with Bike ID :{0}”, Keywords = Keywords.Application, Level = EventLevel.Informational)]
public void BikeStarted(String BikeID){
if (this.IsEnabled()) //// = always returns false
this.WriteEvent(102,BikeID);
It looks like 'Azure Web Apps' cannot listen to ETW events.
https://azure.microsoft.com/en-in/documentation/articles/choose-web-site-cloud-service-vm/
Areas of diagnostics logging and tracing that aren't available to web applications on Azure are Windows ETW events, and common Windows event logs (e.g. System, Application and Security event logs). Since ETW trace information can potentially be viewable machine-wide (with the right ACLs), read and write access to ETW events are blocked. Developers might notice that API calls to read and write ETW events and common Windows event logs appear to work, but that is because WEb Apps is "faking" the calls so that they appear to succeed. In reality, the web app code has no access to this event data
Thanks
I am wondering why the following azure workerrole does not show any diagnostic messages when the role is shutdown:
public class WorkerRole : RoleEntryPoint {
private bool running=true;
public override void Run() {
while (running)
{
Thread.Sleep(10000);
TTrace.WriteLine("working", "Information");
}
Trace.WriteLine("stopped", "Information");
}
public override bool OnStart()
{
Trace.WriteLine("starting", "Information");
return base.OnStart();
}
public override void OnStop() {
Trace.WriteLine("stopping", "Information");
running = false;
base.OnStop();
}
}
I can see the events 'starting' and 'working' in the diagnostic logs, but the Onstop method does not log anything. I was wondering if it's even called so I injected some code in the OnStop() method to write out some data. In fact the data was written as expected which proves that the method is called, it's just that I don't get any logs. Any ideas how to Trace my shutdown code?
My first and best guess is that the Diagnostics Agent does not have time to transfer the trace out to storage for you to see it. Traces are first logged locally on the VM, then the agent will transfer them off (OnDemand or Scheduled) depending on how you have configured it. Once the VM shuts down, the agent is gone too and cannot transfer it off.
Tracing in OnStop is not supported and if you manage to get it working via On-Demand Transfer (http://msdn.microsoft.com/en-us/library/windowsazure/gg433075.aspx ) it's likely to not work in the next release. Note, tracing in Web Role OnStart does not work either. See my blog post http://blogs.msdn.com/b/rickandy/archive/2012/12/21/optimal-azure-restarts.aspx to fix that. Also see my blog post for instructions on view real time OnStop trace data with DbgView.
The OnStop method should be used only to delay shutdown until you've cleaned up - so you shouldn't have much code in there to trace. Again, see my blog for details.