2

Here i have a webjob function using servicebus triggers and outputs. I'd like to set a different configuration for output and input.

public static void OnPush(
    [ServiceBusTrigger("%PushProcessor.InputTopicName%", "%PushProcessor.InputTopicSubscriptionName%", AccessRights.Listen)]
    BrokeredMessage message,
    [ServiceBus("%PushProcessor.OutputTopicName%", AccessRights.Send)]
    out BrokeredMessage output
    )

I see in latest api that one can control the job host with service bus extensions.

JobHostConfiguration config = new JobHostConfiguration
        {
            StorageConnectionString = ConfigHelpers.GetConfigValue("AzureWebJobsStorage"),
            DashboardConnectionString = ConfigHelpers.GetConfigValue("AzureWebJobsDashboard"),
            NameResolver = new ByAppSettingsNameResolver()
        };

config.UseServiceBus(new ServiceBusConfiguration
        {
            MessageOptions = new OnMessageOptions {
                MaxConcurrentCalls = 2,
                AutoRenewTimeout = TimeSpan.FromMinutes(1),
                AutoComplete = true,
            },
            ConnectionString = ConfigHelpers.GetConfigValue("InputServiceBusConnectionString"),
        });

Unfortunately i see no control for the connection string for the output. I'd like a different connection string (different namespace/access rights) to be used for inputs versus outputs.

Perhaps the api can support registering named jobhostconfigurations to a jobhost, and referring to that name in the attributes for the trigger/output. Anyways if there is a way to do this let me know.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
TravisK
  • 129
  • 8

1 Answers1

1

Yes, also in the latest beta1 release you'll see that there is now a ServiceBusAccountAttribute that you can apply along with the ServiceBusTrigger/ServiceBus attributes. For example:

    public static void Test(
        [ServiceBusTriggerAttribute("test"),
         ServiceBusAccount("testaccount")] BrokeredMessage message)
    {
        . . .
    }

We've done the same for all the other attribute types (Queue/Blob/Table) via StorageAccountAttribute. These account attributes can be applied at the class/method/parameter level. Please give this new feature a try and let us know how it works for you. Also, see the release notes for more details.

mathewc
  • 13,312
  • 2
  • 45
  • 53
  • hmm still having troubles.public static void OnPush( [ServiceBusTrigger("%PushProcessor.InputTopicName%", "%PushProcessor.InputTopicSubscriptionName%", AccessRights.Listen)] BrokeredMessage msg, [ServiceBus("%PushProcessor.OutputTopicName%", AccessRights.Send)] [ServiceBusAccount("PushProcessor.OutputServiceBusConnectionString")] out BrokeredMessage output ) Do i have to use this with a custom messagingprovider? I have an entry for connection string in servicebusaccount in appsettings. getting: FunctionIndexingException – TravisK Oct 15 '15 at 23:59
  • Make sure the connection string in your settings is prefixed with the usual "AzureWebJobs" prefix. For example, if you're using [ServiceBusAccount("SBOutput")] your connection string name in settings should be "AzureWebJobsSBOutput". – mathewc Oct 16 '15 at 00:37
  • Cool that work. Gotta say not entirely clear from exception that i needed to do that. Nothing in exception mentions what connection string it was looking up. Here is inner exception: Configuration is missing required information. Make sure the property 'Endpoint' is defined as part of 'Microsoft.ServiceBus.ConnectionString' key within 'appSettings' section, or Windows Azure configuration settings."} – TravisK Oct 16 '15 at 22:05
  • We'll improve the error message in this case, thanks. – mathewc Oct 17 '15 at 04:05
  • 1
    Is there an update in the pipeline to take this from Environment variables? We have a standard config string that gets replaced with Octopus for our own framework and we'd rather not have it in different places – GrahamB Jul 05 '18 at 17:33