IBusControl.Publish to another URL

93 views
Skip to first unread message

tianyingwang

unread,
Dec 19, 2016, 4:31:56 PM12/19/16
to masstransit-discuss
I am trying to publish a message to another url on the RabbitMQ in the publish/subscribe model.

In MassTransit 2.10.0, I can use IBus to publish a message to another uri with a correlationId.
    _bus.SendRequest(AnotherUri_B, correlationId, message);


But in MassTransit 3.4, I don't see how to use IBusControl to publish message to AnotherUri_B together with a correlationId. However I can publish to myself to the Uri (originalUri_A) that is originally created with the bus.

Could you give me some suggestions or point me to some sample code?

Thank you so much,

Dru Sellers

unread,
Dec 19, 2016, 4:47:33 PM12/19/16
to masstrans...@googlegroups.com
So, you want to send a message to a given endpoint with a specific correlationId. the correlation id is set on the message payload itself so you should just be able to do _bus.GetSendEndpoint(new Uri("rabbitmq://")).Result.Send(new Message { CorrelationId = NewId.New });

Although to be clear, if you are using a send endpoint you are, by definition, not doing a "publish" in the classic terminology.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstransit-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/1436b5c5-915a-49ef-9406-aecf1982f5d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tianyingwang

unread,
Dec 20, 2016, 12:00:47 PM12/20/16
to masstransit-discuss
Dru, thank you for your quick response.

By using endpoint.Send I can send the message to the url I target, however it doesn't send the correct message format. 

Now the issue is the correlationId, it cannot be part of the message since  message itself is an interface we talk to another third party, that message type is fixed and we cannot change.

With the old API, "_bus.SendRequest(AnotherUri_B, correlationId, message);", we sent the following payload which can be interpreted by the other end:

   {

       "requestId": "This is the correlatioin id",
       "destinationAddress": "This is the correct endpoint sending to",
       "headers": {},
       "message": { This is the message details},
       "messageType": [ "This the message type for above message so that other side will consume by the type handler"],
       "responseAddress": "This is the correct response address so that other party will send back the response."

   }

But with the new API, "endpoint.Send(new { requestId = correlationId, message = request });", here is the payload format:

   {
     "messageId": "0f0c0000-b04b-00ff-fe30-08d428f37df7",
     "conversationId": "0f0c0000-b04b-00ff-ff23-08d428f37df7",
     "sourceAddress": "this is the correct source address",
     "destinationAddress": "This is the correct destimatioin address",
     "messageType": [],
     "message": {

    "requestId": "This is the correct correlation id",
    "message": {This is the correct message compatible with another third party interface},
}
      "headers": {},
   }

Add it is missing the "ResponseAddress".

Could you give me some suggestions how to make the correlation id outside the inter message? And how to add Response Address into the end point?

Something like "endpoint.Send(request,  correlationId)" would be better. here request is the payload message, correlation id is another field in the api.

Thanks a lot,





On Monday, December 19, 2016 at 3:47:33 PM UTC-6, Dru wrote:
So, you want to send a message to a given endpoint with a specific correlationId. the correlation id is set on the message payload itself so you should just be able to do _bus.GetSendEndpoint(new Uri("rabbitmq://")).Result.Send(new Message { CorrelationId = NewId.New });

Although to be clear, if you are using a send endpoint you are, by definition, not doing a "publish" in the classic terminology.
On Mon, Dec 19, 2016 at 3:31 PM, tianyingwang <tianyi...@gmail.com> wrote:
I am trying to publish a message to another url on the RabbitMQ in the publish/subscribe model.

In MassTransit 2.10.0, I can use IBus to publish a message to another uri with a correlationId.
    _bus.SendRequest(AnotherUri_B, correlationId, message);


But in MassTransit 3.4, I don't see how to use IBusControl to publish message to AnotherUri_B together with a correlationId. However I can publish to myself to the Uri (originalUri_A) that is originally created with the bus.

Could you give me some suggestions or point me to some sample code?

Thank you so much,

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

Alexey Zimarev

unread,
Dec 20, 2016, 12:34:14 PM12/20/16
to masstransit-discuss
You can supply a delegate that sets the headers, in send and in publish:

        public async Task Consume(ConsumeContext<MyMessage> context)
        {
            var ep = await context.GetSendEndpoint(new Uri("rabbitmq://somewhere"));
            var message = new Commands.MyOtherMessage(1, 2, 3);
            await ep.Send(message, c => c.Headers.Set("CorrelationId", Guid.NewGuid().ToString()));
        }



Chris Patterson

unread,
Dec 20, 2016, 12:57:29 PM12/20/16
to masstrans...@googlegroups.com
If you were using the SendRequest(), you can use the new MessageRequestClient():


This will set the proper headers, including RequestId and ResponseAddress, as was previously done using the original v2.x API.

You can also use bus.Request(), which was similar to the previous bus.SendRequest() - but is now async and can be awaited.


To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsubscribe...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

tianyingwang

unread,
Dec 21, 2016, 12:42:58 PM12/21/16
to masstransit-discuss
Alexey, thank you so much for your reply. By using your suggestion, the code put the correlationId inside the headers section, like this:

   {
     "message": {
}
      "headers": {
             "correlationId": "The guid"
           },
   }

The other party actually looking for this:

   {
     "correlationId": "The guid"
     "message": {
}
      "headers": {
           },
   }

Any other suggestion?

Thank you so much again.

tianyingwang

unread,
Dec 21, 2016, 12:50:59 PM12/21/16
to masstransit-discuss
Thank you so much Chris,

The MessageRequestClient doesn't seems to have SendRequest api, it does have the Request api which has the request and a cancellationToken, Could you give me a little details how to send the correlationId together with the responseAddress? I am using 3.4.1, maybe that is the different.

Also, Bus.Request is good except the correlationId is set inside Headers section which the other party cannot recognize based our agreement. Do you have any suggestion I can make the customized field called requestId in parallel with the message and headers like this?

   {
     "requestId": "The guid"
     "message": {
}
      "headers": {
           },
   }

Thanks again for all your help.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

Chris Patterson

unread,
Dec 21, 2016, 7:53:16 PM12/21/16
to masstrans...@googlegroups.com
You might want to look again, both the message request client and the bus.Request method do the same thing and are functionally equivalent to what you used in MassTransit 2, down to the wire format and message in JSON. 

__
Chris Patterson




To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages