Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Why is an object inside an object not received by the Masstransit consumer when the contract is in a nuget package

$
0
0

I have a Masstransit publisher and a consumer (both below).

The message that is sent is

    public class SendEmailContract    {        public List<Attachment> Attachments { get; internal set; }        public string AddressFrom { get; internal set; }        public string AddressTo { get; internal set; }        public string AddressCC { get; internal set; }        public string AddressBCC { get; internal set; }        public string Subject { get; internal set; }        public string Data { get; internal set; }        public string TemplateCode { get; internal set; }        public string EmailHtml { get; internal set; }        public bool WithoutTemplate { get; internal set; }    }    public class Attachment    {        public string Name { get; internal set; }        public string ContentType { get; internal set; }        public byte[] Content { get; internal set; }    }

The email contract has a list of attachments.

When I run the sample publisher the email contract together with the attachments is received by the consumer.

When the email contract is in a nuget package (i.e. in a separate DLL) the email contract is received but the attachments are null.

Questions Why is the attachments field null when the contract is in a separate DLL? (the question might be vague, but I do not know how to reduce this problem further, any help and ideas will be greatly appreciated)

Publisher below

using MassTransit;using System;using System.Collections.Generic;using System.Threading;using System.Threading.Tasks;namespace ConsolePublisher{    class Program    {        static async Task Main(string[] args)        {            Console.WriteLine("Hello World!");            var busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>            {                cfg.Host("localhost", "/", h =>                {                    h.Username("guest");                    h.Password("guest");                });            });            var source = new CancellationTokenSource(TimeSpan.FromSeconds(10));            await busControl.StartAsync(source.Token);            var message = new SendEmailContract            {                AddressFrom = "addressfrom@mail.com",                AddressTo = "addressto@mail.com",                AddressCC = "cc1@mail.com,cc2@email.com",                AddressBCC = "bcc1@mail.com,bcc2@mail.com,bcc3@mail.com",                Subject = $"Test subject email {DateTime.Now}",                Data = @"<Data><CustomerName>NewReg NewReg</CustomerName><Barcode>bc12345678us</Barcode><URL>https://example.com</URL><ServiceTitle>Priority</ServiceTitle></Data>",                TemplateCode = "emailtemplate123",                EmailHtml = "emailhtml",                WithoutTemplate = false,                Attachments = new List<Attachment>                {                    new Attachment                    {                        Name = "Attachment1.txt",                        ContentType = "txt",                        Content = new byte[] { 1,2,3,4,5,6},                    },                    new Attachment                    {                        Name = "Attachment2.txt",                        ContentType = "txt",                        Content = new byte[] { 2,2,3,4,5,7},                    }                },            };            await busControl.Publish<SendEmailContract>(message);            await busControl.StopAsync();        }    }    public class SendEmailContract    {        public string AddressFrom { get; internal set; }        public string AddressTo { get; internal set; }        public string AddressCC { get; internal set; }        public string AddressBCC { get; internal set; }        public string Subject { get; internal set; }        public string Data { get; internal set; }        public string TemplateCode { get; internal set; }        public string EmailHtml { get; internal set; }        public bool WithoutTemplate { get; internal set; }        public List<Attachment> Attachments { get; internal set; }    }    public class Attachment    {        public string Name { get; internal set; }        public string ContentType { get; internal set; }        public byte[] Content { get; internal set; }    }}

Consumer below

using GreenPipes;using MassTransit;using MassTransit.ConsumeConfigurators;using MassTransit.Definition;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;using Microsoft.Extensions.Logging;namespace ConsuleConsumer{    public class Program    {        public static async Task Main(string[] args)        {            var services = new ServiceCollection();            services.AddMassTransit(x =>            {                x.AddConsumer<EmailConsumer>(typeof(EmailConsumerDefinition));                x.SetKebabCaseEndpointNameFormatter();                x.UsingRabbitMq((context, cfg) =>                {                    cfg.Host("rabbitmq://localhost");                    cfg.ConfigureEndpoints(context);                });            });            var serviceProvider = services.BuildServiceProvider();            var bus = serviceProvider.GetRequiredService<IBusControl>();            await bus.StartAsync();            Console.WriteLine("Press any key to exit");            await Task.Run(() => Console.ReadKey());            Console.WriteLine("Now stopping bus...");            await bus.StopAsync();            Console.WriteLine("Bus stopped");            Console.ReadKey();        }    }    public class EmailConsumer :IConsumer<ConsolePublisher.SendEmailContract>    {        readonly ILogger<EmailConsumer> _logger;        public EmailConsumer ()        {            Console.WriteLine("starting email consumer");        }        public EmailConsumer(ILogger<EmailConsumer> logger)        {            _logger = logger;        }        public async Task Consume(ConsumeContext<ConsolePublisher.SendEmailContract> context)        {            _logger.LogInformation("Email:", context.Message.Data);        }    }    public class EmailConsumerDefinition :    ConsumerDefinition<EmailConsumer>    {        public EmailConsumerDefinition()        {            // override the default endpoint name            EndpointName = "email-service";        }        protected override void ConfigureConsumer(IReceiveEndpointConfigurator endpointConfigurator,            IConsumerConfigurator<EmailConsumer> consumerConfigurator)        {            endpointConfigurator.UseScheduledRedelivery(r => r.Intervals(TimeSpan.FromSeconds(10)));            endpointConfigurator.UseInMemoryOutbox();        }    }}namespace ConsolePublisher{    public class SendEmailContract    {        public string AddressFrom { get; internal set; }        public string AddressTo { get; internal set; }        public string AddressCC { get; internal set; }        public string AddressBCC { get; internal set; }        public string Subject { get; internal set; }        public string Data { get; internal set; }        public string TemplateCode { get; internal set; }        public string EmailHtml { get; internal set; }        public bool WithoutTemplate { get; internal set; }        public List<Attachment> Attachments { get; internal set; }    }    public class Attachment    {        public string Name { get; internal set; }        public string ContentType { get; internal set; }        public byte[] Content { get; internal set; }    }}}

Versions using in the publisher

  1. MassTransit.RabbitMQ 8.0.5

Versions using in the consumer

  1. MassTransit.RabbitMQ 7.0.6

Update

  1. If I use MassTransit.RabbitMQ 7.0.6 in the publisher the problem is solved.
  2. When the publisher uses version 8.0.5, if I switch off the consumer and get the messages in the RabbitMQ website (http://localhost:15672/) then the attachments are missing.

Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>