1

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

НЕ работает

// 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}"); 
     }  

Автобусное меня Ssage основано на этом классе

сообщения автобуса
[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(); 

ответ

0

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

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

 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); 
    }