Reputation: 152
I'm having problem with MassTransit in Request-Respond model (using MassTransit.RabbitMQ 3.0.14).
TLDR; Request-Respond does not work when response type is List/IEnumerable.
In client I'm creating instance of IRequestClient:
var RequestObjects = busControl.CreateRequestClient<MyObjectsRequest, List<MyObject>>(
new Uri(configuration["MassTransit:ServerAddress"] + "/" + configuration["MassTransit:TestQueueName"]),
TimeSpan.FromSeconds(15));
Next, I call server for a response:
RequestObjects.Request(new MyObjectsRequest{ Id = 1 });
On server side I have registered consumer:
public async Task Consume(ConsumeContext<MyObjectRequest> context)
{
var myList = new List<MyObject>
{
new MyObject { Id = 1 },
new MyObject { Id = 2 }
}
context.Respond(myList);
}
And the problem is that response go to some temporary _skipped queue (I'm tracking it via RabbitMQ's web panel) and I'm getting RequestTimeOutException.
I've tried also with IEnumerable<>
- same thing.
In fact, Array<MyObject>
works well - response is going back to my client.
AFAIR when I was using MassTransit 2.x subscribing on Lists worked well. Is there a possibility to do the same on MassTransit 3.x?
What's curious, the message type seems to be erased when it's getting to RabbitMQ while I'm using List/IEnumerable:
The snippet of the messageType when single object is sent:
And the snippet of the messageType when Array of the objects is sent:
Upvotes: 0
Views: 1554
Reputation: 33278
Using an array is definitely preferred over a List<T>
or an IEnumerable<T>
- for reasons of which are different. Arrays are immutable (generally, anyway) and cannot typically be modified.
That being said, I'm pretty sure that all of the signatures you've mentioned should work if you're using JSON, BSON, or XML. The relevant line of code is at https://github.com/MassTransit/MassTransit/blob/develop/src/MassTransit/Serialization/JsonConverters/ListJsonConverter.cs#L59 -- clearly both List
and IEnumerable
are present.
Do you have a failing unit test? If so, can you share it?
Upvotes: 1