по какой-то причине я не могу понять, как вытащить мой объект из моей очереди и десериализовать его обратно в то, что он был помещен в него (An AccountEventDTO ).
Функция Azure успешно помещает объект в очередь:
[FunctionName("AccountCreatedHook")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req,
TraceWriter log, [ServiceBus("topic-name", Connection = "BusConnectionString", EntityType = Microsoft.Azure.WebJobs.ServiceBus.EntityType.Topic)] IAsyncCollector<BrokeredMessage> accountCreatedTopic)
{
var accountEvent = await req.Content.ReadAsAsync<AccountEventDTO>();
if (accountEvent != null && accountEvent.Name != null)
{
// Serialization
var bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(accountEvent));
var memoryStream = new MemoryStream(bytes, writable: false);
var message = new BrokeredMessage(memoryStream) { SessionId = Guid.NewGuid().ToString() };
await accountCreatedTopic.AddAsync(message);
return req.CreateResponse(HttpStatusCode.OK, "Account successfully added to topic.");
}
return req.CreateResponse(HttpStatusCode.BadRequest, "Account was not formed well.");
}
Функция Azure извлекает объект из очереди:
[FunctionName("AccountCreatedSubscriber")]
public static void Run([ServiceBusTrigger("topic-name", "license-keys", Connection = "BusConnectionString")]BrokeredMessage accountEvent, ILogger log)
{
// ERROR on this line during deserialization
var account = accountEvent.GetBody<AccountEventDTO>();
var accountAddedEvent = Mapper.Map<AccountEventDTO, AccountAddedEvent>(account);
_accountHandler.Handle(accountAddedEvent);
GenericLogger.AccountLogging(log, accountAddedEvent);
}
Сообщение об ошибке:
AccountEventDTO:
public class AccountEventDTO : IAccountEvent
{
public string Name { get; set; }
public string SugarId { get; set; }
public string AccountSubTypeRaw { get; set; }
public AccountType AccountType { get; set; } = AccountType.Customer;
public AccountSubType? AccountSubType { get; set; } = null;
public string Phone { get; set; }
public string PhoneAlternate { get; set; }
public string BillingAddressCity { get; set; }
public string BillingAddressCountry { get; set; }
public string BillingAddressPostalCode { get; set; }
public string BillingAddressState { get; set; }
public string BillingAddressStreet { get; set; }
public string ShippingAddressCity { get; set; }
public string ShippingAddressCountry { get; set; }
public string ShippingAddressPostalCode { get; set; }
public string ShippingAddressState { get; set; }
public string ShippingAddressStreet { get; set; }
public string Website { get; set; }
}