Не удается привязать членов ServiceBusTrigger BrokeredMessage к пути больших двоичных объектов в пакете SDK Azure WebJobs.

Я не могу добавить динамическую привязку каких-либо членов Service Bus BrokeredMessage с помощью пакета SDK Azure WebJobs.

НЕ работает

// using properties on BrokeredMessage object
public static void ProcessDup([ServiceBusTrigger("dup")] **BrokeredMessage** q, [Blob("dup/{Label}")] string json, TextWriter log)
        {
            log.WriteLine($"Content(Id) {q.Label}\r\nBlob {json}");
            Console.WriteLine($"Content(Id) {q.Label}\r\nBlob {json}");
        }       

// using properties inside of the BrokeredMessage.Properties
public static void ProcessDup([ServiceBusTrigger("dup")] **BrokeredMessage** q, [Blob("dup/{JsonFilename}")] string json, TextWriter log)
        {
            log.WriteLine($"Content(Id) {q.JsonFilename}\r\nBlob {json}");
            Console.WriteLine($"Content(Id) {q.JsonFilename}\r\nBlob {json}");
        }       

Это дает мне следующие сообщения, когда он обрабатывает сообщения от служебной шины

  Function had errors. See Azure WebJobs SDK dashboard for details. Instance ID
is '0a957645-f042-4dca-a38f-643229fbbc21'
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while execut
ing function: Functions.ProcessDup ---> System.InvalidOperationException: Except
ion binding parameter 'json' ---> System.ArgumentNullException: Value cannot be
null.
Parameter name: bindingData
   at Microsoft.Azure.WebJobs.Host.Bindings.BindingDataPathHelper.ConvertParamet
ers(IReadOnlyDictionary`2 bindingData)
   at Microsoft.Azure.WebJobs.Host.Blobs.ParameterizedBlobPath.Bind(IReadOnlyDic
tionary`2 bindingData)
   at Microsoft.Azure.WebJobs.Host.Blobs.Bindings.BlobBinding.<BindAsync>d__0.Mo
veNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding`1.<BindCore
Async>d__7.MoveNext()
   --- End of inner exception stack trace ---
   at Microsoft.Azure.WebJobs.Host.Executors.DelayedException.Throw()
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithWatche
rsAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggin
gAsync>d__2c.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggin
gAsync>d__13.MoveNext()
   --- End of inner exception stack trace ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggin
gAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<TryExecuteAsync>d
__1.MoveNext()

РАБОТАЕТ

public static void ProcessDup([ServiceBusTrigger("dup")] **TheDup** q, [Blob("dup/{JsonFilename}")] string json, TextWriter log)
        {
            log.WriteLine($"Content(Id) {q.JsonFilename}\r\nBlob {json}");
            Console.WriteLine($"Content(Id) {q.JsonFilename}\r\nBlob {json}");
        }       

Сообщение служебной шины основано на этом классе.

  [DataContract(Name = "TheDup", Namespace = "")]
    public class TheDup
    {
        [DataMember]
        public Guid Id { get; set; }
        public string JsonFilename => $"{Id}.json";
        [DataMember]
        public string Json { get; set; }
    }

Сообщение служебной шины добавляется с помощью

var client = QueueClient.CreateFromConnectionString(_queueConnectionString, _queueName);
var message = new BrokeredMessage(new TheDup() {Id = id, Json = sSourceData?.Length > 128 ? string.Empty : sSourceData})
{
 SessionId = sessionid == null ? id.ToString() : sessionid.ToString(),
 Label = $"{id}.json"
};
message.Properties.Add(new KeyValuePair<string, object>("JsonFilename", $"{id}.json"));
client.Send(message);
client.Close();



Ответы (1)


Как вы обнаружили, вы можете включать только параметры привязки, такие как dup/{JsonFileName}, при привязке к POCO, который определяет эти элементы. Это по дизайну.

Если это не работает для вас, и вам действительно нужно выполнить динамическую императивную привязку, вы можете использовать IBinder для выполнения привязки больших двоичных объектов в своем коде, а не в привязке параметров. Вот простой пример:

        public static void BlobIBinder(
            [QueueTrigger("persons")] Person persons, 
            IBinder binder)
        {
            var blobAttrib = new BlobAttribute("persons/" + persons.Name + "BlobIBinder");
            var writer = binder.Bind<TextWriter>(blobAttrib);
            writer.Write("Hello " + persons.Name);
    }
person mathewc    schedule 07.01.2017