Anypoint MQ REST APIs
MuleSoft has provided out of the box Anypoint MQ REST APIs to push message to Anypoint MQ – right now it only support JSON request while calling the APIs
For this we have to make 2 REST call to push message to MQ
First Call to get access token
REST POST – https://mq-us-east-1.anypoint.mulesoft.com/api/v1/authorize
Copy client id and secret from Anypoint platform – (to know more how to copy)
Create REST call in postman
Set Key Headers
- Accept – application/json
- Content-Type – application/x-www-form-urlencoded
Set Query Parameter
- client_id – <id>
- client_secret – <secret>
- grant_type – client_credentials
Once request is sent then we can see access_token in response – validity of access token is for some minutes only and after sometime we have to again regenerate for new calls
Second call – to push message to Anypoint MQ and for this we have to create the URL like –
- orgId and envId – we can get from earlier call response
- MQname – name of the MQ on which we want to send message
- MessageId – Message id
e.g.
Copy the access token from last call and add it as Bearer Token in Authorization
Add same http header as before
Now make a request to push message after setting up the Body
And we see the successful response and same message is now available in MQ
Please note – while send a message body the JSON structure should be like this
{ "body" : "My message payload" }
So the content of body element should be of string so in this case if we have to pass JSON structure then we have to remove all the new line character from JSON String and add escape sequence – \
e.g.
{ "body" : "{\"Hello\":\"World\"}" }
Thanks for such a valuable informative post on mule soft. By going through it most of my ongoing doubts regarding mule soft have been cleared. Looking forward for more of such informative posts.
For more details on Mule soft Training In Hyderabad, please vist https://www.kellytechno.com/Hyderabad/Course/MuleSoft-Training-In-Hyderabad
nice post
Can you specify these AMQ-related endpoints in MuleSoft Exchange definitions and or as Design Center resources during RAML/OAS modelling ??
I’m so happy to have read this blog. Thank you for sharing, sir.