Try PubSub+

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

andrew_j_robertsandrew_j_roberts Member, Employee Posts: 7 Solace Employee

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

  • AaronAaron Member, Moderator, Employee Posts: 192 Solace Employee

    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..?

  • andrew_j_robertsandrew_j_roberts Member, Employee Posts: 7 Solace Employee

    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?

  • AaronAaron Member, Moderator, Employee Posts: 192 Solace Employee

    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.

Sign In or Register to comment.