🎄 Happy Holidays! 🥳

Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.

Happy Holidays!

Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.

How do I send a reply in Microgateway mode to a dynamic topic?

Let's say I'm running an event broker in Microgateway mode and am handling REST requests with a streaming consumer/processing application. How do I send a reply to a dynamic topic?

An example of why you'd want the reply on a hierarchical topic could be a req/reply validation flow, and having a downstream application (fraud detection, account alerts, etc.) interested in all replies that REJECT the verification request.

I can’t think of a way to publish the response of the HTTP flow to a hierarchical topic without double publishing, once to the automatically-configured P2P replyTo topic (#P2P/#rest-__/{verb}/{requestTopic}) and once to a dynamically populated hierarchical topic. Using Messaging mode or one of the other client libraries, I'd be able to configure the replyTo topic—but doesn't seem like there's an option for that in Microgateway mode.

Is the double publishing an anti-pattern? Any ideas?

Comments

  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 644 admin

    Hey @andrew_j_roberts . Great question! Looking through the docs (https://docs.solace.com/RESTMessagingPrtl/Solace-REST-Message-Encoding.htm#_Toc426703633), I do see a way to specify the "reply-to", but unfortunately, it's only for REST Messaging mode, not Gateway mode:

    I guess it's because in Gateway mode, the broker is handling everything automatically, sets up the funny-looking #P2P/... reply-to topic automatically. So if your Replier application absolutely needs to send the reply message to a constructed, defined topic hierarchy, I think you either have to:

    a) double publish
    b) use a Processor-type application (1-in-1-out), which is essentially just offloading that responsibility to another app

    May I ask though: what use case or functional capability it that you are trying to achieve? Perhaps there's another way..?

  • [Deleted User]
    [Deleted User] Posts: 0 ✭✭

    May I ask though: what use case or functional capability it that you are trying to achieve?

    The idea would be to wire tap an existing HTTP req/reply flow and generate actionable events based on it. So in the initial example I gave for account verification, it's really the error condition where the account was NOT able to be verified that other apps might care about. Instead of point-to-point communication between the initial app and N # of fraud applications (N number today, Z number tomorrow...) that care about that error condition, it'd be great if there was a way to put the error message on the event mesh. What do you think?

  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 644 admin

    Ok, so you're hoping that you could build a response topic that contains "ok" or "error" or something in the topic, eh? And then filter based on that..?

    But (if I read you correctly) what you're really trying to do is filter on the response somehow. Obviously, if you could use Solace hierarchical topics directly, you'd embed something in the topic, but what other options are there? Another option which might work for an existing REST flow is took look at the HTTP response code. The backend REST service will/should pass along a response code, right? 200 OK, or 40x for something bad? HTTP codes are passed through the broker as User Properties on the message. And while we can't do topic filtering on that, you could use a Selector to look for certain error codes? This might actually be one of the good uses of a Topic Endpoint in Solace, because it performs its Selector on ingress, rather than a Queue which stores all messages, and performs Selectors on egress based on a client.

    ... goes and tries ...

    So yes, you can definitely do this! I made a Topic Endpoint "te1", and then used a Solace client (SdkPerf in my case) to connect a client to that TE and specify a subscription (as you had above: #P2P/v:*/#rest-*/POST/> for all POST responses) (maybe use the specific topic rather than > to be more selective) as well as a Selector JMS_Solace_HTTP_status_code>299.

    BTW, I tested this using SdkPerf C and a Topic Endpoint called te-rest-errors:

    ./sdkperf_c -cip=localhost -sdl=te-rest-errors -stl="#P2P/v:*/#rest-*/>" -ssl="JMS_Solace_HTTP_status_code>299" -md
    

    And then (after having configured the VPN for MicroGateway and RDP to a backend service -- SEMP in my case) I got this on the command line when issuing a bad request:

    ^^^^^^^^^^^^^^^^^^ Start Message ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    Destination:                            Topic '#P2P/v:cd6c1f921db8/#rest-06c7bdc3dedfb2c5/GET/SEMP/v2/config/msgVpns'
    ApplicationMessageId:                   ID:Solace-c6e9493cdae8b1ed
    CorrelationId:                          ID:Solace-c6e9493cdae8b1ed
    HTTP Content Type:                      application/json
    Class Of Service:                       COS_1
    DeliveryMode:                           NON-PERSISTENT
    Message Id:                             3
    Reply Message
    User Property Map:
      Key 'JMS_Solace_HTTP_field_Date' (STRING) Tue, 27 Apr 2021 06:41:26 GMT
      Key 'JMS_Solace_HTTP_field_Server' (STRING) Solace_VMR/9.2.0.14
      Key 'JMS_Solace_HTTP_field_Cache-Control' (STRING) no-cache
      Key 'JMS_Solace_HTTP_field_WWW-Authenticate' (STRING) Basic realm="Unauthorized"
      Key 'JMS_Solace_HTTP_field_Access-Control-Allow-Credentials' (STRING) true
      Key 'JMS_Solace_HTTP_field_Access-Control-Allow-Headers' (STRING) Authorization, Content-Type, X-Requested-With
      Key 'JMS_Solace_HTTP_field_Access-Control-Allow-Methods' (STRING) GET, POST, PUT, PATCH, DELETE, OPTIONS
      Key 'JMS_Solace_HTTP_field_Strict-Transport-Security' (STRING) max-age=31536000
      Key 'JMS_Solace_HTTP_status_code' (UINT16) 401
      Key 'JMS_Solace_HTTP_reason_phrase' (STRING) Unauthorized
    Binary Attachment String:               len=318
    <SNIP>
    

    So if you really wanted to, you could Selector on ANY of those User Properties that get populated by the MicroGateway!

    Nice. I like this.

  • Frankee787
    Frankee787 Member Posts: 10

    Hello,
    I know this question is bit old is pertaining to get a response in a **gateway **mode. However is it possible to get back the response in the **messaging **mode?

    I have an RDP configured. Would it be possible to get back the response into another topic/queue ? The purpose is purely for auditing the responses of the RDP service calls.

    Best Regards,
    Franklin

  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 644 admin

    Hey @Frankee787 ..! I somehow missed this post you made back in December. Apologies for that. Unfortunately, (currently) there's no easy way to get the response code from an RDP that is configured in Messaging mode. The REST response goes back to the REST Consumer ends there.

    HOWEVER! A couple months ago I was helping a colleague with a similar ask, and thought it would be possible to "glue together" two Message VPNs (easy if running the software broker yourself), where you have one VPN configured as Messaging and one configured as Gateway. And then the Messaging VPN RDP simply POSTs to the incoming REST port of the Gateway VPN so the REST request has to "go through there", which means that the REST response comes back as a message to pass back to the RDP in the Messaging VPN.

    Here's a diagram I made for my colleague. "SF" in this case was SalesForce, trying to push into that:


    I started writing some code for a "REST Correlator" app that connected to the Gateway VPN and listened to all the requests and responses as messages, and would (should?) publish a message when something goes wrong. https://github.com/aaron-613/solace-rest-response-correlator

    Not sure if this would help, but thought I'd reply here. I'm sure the performance isn't spectacular, because you have two RDPs now, but it does work.

  • Frankee787
    Frankee787 Member Posts: 10
    edited May 2022 #7

    Thanks @Aaron . That looks like a neat trick.