Is it possible to get at the underlying BrokeredMessage in a web job with a service bus trigger from within the IJobActivator? This would be very useful in a multi-tenant scenario.
I'm using a custom IJobActivator with Unity to instantiate my jobs. From within my UnityJobActivator class, I'd like to be able to look at the underlying BrokeredMessage and pull some custom properties off of it, such as "Tenant", which all of my messages have. This would allow me to inject the appropriate database connection, or configuration objects into my job class before it is executed.
Below is an example where I want to inject ITenantConfiguration into the job, but have it be based on a BrokeredMessage custom property. I could do this if I could get access to the BrokeredMessage from within my UnityJobActivator.
public class CustomJob
{
private const string Subscription = "subscription";
private const string Topic = "topic";
private ITenantConfiguration config;
public CustomJob(ITenantConfiguration config)
{
// This configuration depends on the Tenant property of the BrokeredMessage
this.config = config;
}
public void Handle([ServiceBusTrigger(Topic, Subscription)] MyMessage myMessage)
{
// Do something with myMessage and the appropriate configuration
}
}