What I am trying to do is something along the lines of this :
public class BaseQueueTrigger
{
private readonly string _triggerNamee;
public BaseQueueTrigger(string triggerNamee)
{
_triggerNamee = triggerNamee;
}
public void ProcessQueueMessage(
[QueueTrigger("%" + _triggerNamee + "%")] string message)
{
ProcessMessage(message);
}
public void ProcessServiceBusMessage(
[ServiceBusTrigger("%" + _triggerNamee + "%")] Message message)
{
ProcessMessage(Encoding.UTF8.GetString(message.Body));
}
protected virtual void ProcessMessage(string message)
{
Console.WriteLine($"Base class processing message: {message}");
}
}
What I would like is to have the child class send the queue name via the constructor to set up the endpoints and then have the individual processing of said endpoints happen in the child class once a trigger is hit.
The problem is that this requires a literal constant as the trigger name (compile time) and I am not sure if this approach is even possible.
Any help would be awesome :)
I tried creating a constant value in the child class and tried accessing it from the parent class via reflection but could not get it as a compile time constant value.
I have also considered to use the name of the child class as the queue trigger but will just be to impractical.
The
%TriggerName%syntax is used in both the QueueTrigger and ServiceBusTrigger attributes. The value ofTriggerNameis passed to the constructor of theChildQueueTriggerclass, which in turn passes it to the constructor of theBaseQueueTriggerclass.When a message is received, the corresponding method in the
child classis called, which in turn calls the corresponding method in thebase class.Code
Sample Output: