How to check size of the anypoint mq queue from anypoint studio? - mulesoft

I have a scenario where if the size of queue exceeds from the 10 queues it should send email alert to the client the logice should be done in Anypoint Studio
how can i check the size of the queue ( Anypoint MQ) using anypoint studio

You can develop a Mule application in Anypoint Studio that calls Anypoint MQ REST API (using the HTTP Request connector) to read the number of messages in a queue. Note that this information is not updated in realtime as the documentation mentions.
Example URL:
https://anypoint.mulesoft.com/mq/stats/api/v1/organizations/ORGANIZATION_ID/environments/ENVIRONMENT_ID/regions/REGION_URL
/queues?destinationIds=DESTINATION_ID
Example OUTPUT:
[
{
"destination": "95bgpyxYsVyFE",
"messages": 0,
"inflightMessages": 0
}
]
Note that you need to get an access token from Anypoint Platform to authorize the HTTP request.

Related

Changing presence status of an agent from third party cloud server to salesforce

How to notify Salesforce cloud from a third part cloud server to change the presence status of an specific agent, who is logged in to Omni-Channel. A presence status can be Available, Away, Busy or Offline.
Do we need to use REST API with Salesforce standard objects to change the presence?
Something like:
https://mydomain.my.salesforce.com/services/data/v56.0/<object> -H `Authorization: Bearer ${token}`
We can use jsforce to send this request.
But, not sure which standard object can be used here, which can update the user presence.
The Base Connector API publishEvent with type SET_AGENT_STATUS is on the client side.
Is there any other techniques to send updates from third-part cloud to Salesforce?

"status code 403" Error while creating file using Mule 4 google drive connector

I have to upload images to google drive through mule integration. I'm facing trouble with <google-drive:file-content> connector. Can someone help me or direct me a tutorial relates to it?
This is the error message while I tried to connect to the google drive
Message : Request returned status code 403
Element : imageuploaderFlow/processors/4 #
imageuploader:imageuploader.xml:39 (Create media file)
Element DSL : <google-drive:create-media-file doc:name="Create media file" doc:id="hhhhhjhj" config-ref="Google_Drive_Connector_Config" contentType="application/octet-stream">
<google-drive:file-content><![CDATA[
#[payload.parts.image.content write "application/octet-stream"]
]]></google-drive:file-content>
</google-drive:create-media-file>
Error type : GOOGLE-DRIVE:CLIENT_ERROR
FlowStack : at imageuploaderFlow(imageuploaderFlow/processors/4 # imageuploader:imageuploader.xml:39 (Create media file))
Google Drive Connector Config
scopes: https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file
connector xml snippet
<google-drive:create-media-file doc:name="Create media file" doc:id="ac59e7fe-e615-fggh-9473-2we5cd73ecb7" config-ref="Google_Drive_Connector_Config" contentType="application/octet-stream">
<google-drive:file-content ><![CDATA[#[payload.parts.image.content write "application/octet-stream"]]]></google-drive:file-content>
</google-drive:create-media-file>
The version of the Google Drive connector is 1.0.1
Ensure that you have Enabled the Google Drive API in your project. Not enabling this also raises a 403 error. Also, mostly, Google API sends pretty clear message when you do something wrong. You can access the detailed HTTP response using error.errorMessage.payload and headers using error.errorMessage.attributes.headers

PubSub stops pulling messages from the topic

We are facing this strange PubSub behaviour when our MDM server is idle over a period of time. We create a topic and a subscription during the server start-up, and our server is programmed to pull the subscription messages from the topic asynchronously using the Receive() function. We are creating the PubSub client using the service account credentials.
What we have observed is that, when we run our MDM server on a MAC machine, we see this RPC error intermittently in our server logs:
{
"error": "rpc error: code = Unauthenticated desc = Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"file": "/opt/bigfix/src/bigfix/mdm-android/internal/pubsub/subscriber.go:50",
"func": "bigfix/mdm-android/internal/pubsub.GetPubSubMessages",
"level": "error",
"module": "mqpublisher",
"msg": "Error receiving Pub/Sub messages",
"time": "2022-03-03T04:50:25Z"
}
Note that this error is caught on the line subscription.Receive() in our code. And, any device enrollment messages post this RPC error, aren’t getting delivered to our PubSub client. When we try to pull the pending messages from the topic in Google console, we are able to see all the undelivered messages there. When we restart our server, PubSub connection is made afresh and all these pending commands are pushed to our PubSub client.
We tried to fix the issue in 2 ways:
The version of PubSub package that we were using was 1.6.1, and we tried to upgrade it to the latest version which is 1.18.0, but the problem still persists
Tried to wrap subscription.Receive() with a retry function so that it can keep retrying upon errors, but still the problem persists.
And no matter if we receive this RPC error or not, our MDM server is not able to pull any messages from the topic when it is idle over a period of time. This behaviour is seen only when our server runs on a MAC machine, and works fine in other operating systems.
Kindly guide us as to fix this issue.
Thanks,
Porkodi

Discord Interprocess Communication - Read Messages

I'd like to abide by TOS but i am having tough time. I'm in paid server where I can't place a bot account. I simply want to consume the message content in my application (currently in python). What can I do? Can I write a hook to consume the messages from the GUI or from the web client? It seems what I want to do is not supported. Any thoughts?
Others have stated that you can apparently use use ipc and messages.read scope or RPC to receive messages but I don't know what resources are available to hook into and get the message content as it comes from the server.
There are multiple ways to read the messages from the client. You could use the Discord API with your account's token, but this is not allowed by the Discord ToS and thus is bannable (self botting). The other way is to use Discord IPC.
Discord IPC allows you to communicate with the Discord client by using named pipes. The default name is discord-ipc-0. You need a Discord application to use it.
The IPC protocol uses the same protocol as RPC, which is documented on Discord Developer Portal. You can also find more information on the IPC protocol on the discord-rpc official repo.
To put it simply, the packets you send through the pipe are serialized that way:
uint32 opcode
uint32 length
byte[length] jsonData
The data is a JSON encoded object, with a unique nonce parameter that is sent back on the answer, a cmd parameter for the command you want to use and optionally args and evt.
You would probably be interested in the AUTHORIZE, AUTHENTICATE, GET_CHANNEL and SUBSCRIBE commands. So I'll explain those four commands here.
But first, you need to connect to the IPC and do the handshake. This is done by sending a message with the opcode 0, your client_id and the protocol version. Here's what the JSON object should look like:
{
"v": 1,
"client_id": 332269999912132097
}
Once you're connected, you should receive a DISPATCH response with the user info. Every message you will send from this point should use the opcode 1
Now, you need to send an AUTHORIZE command This command allows you to ask an OAuth2 code from the client with the specified scopes, which will allow you to use the AUTHENTICATE command. Here, you would want the rpc and messages.read scopes. It should look like this:
{
"nonce": "be9a6de3-31d0-4767-a8e9-4818c5690015",
"cmd": "AUTHORIZE",
"args": {
"client_id": 332269999912132097,
"scopes": "rpc messages.read"
}
}
Please note that you need a redirect uri on your application for this to work.
The client should get a prompt. If he accepts, then your application would receive an oauth2 code that you can use to authenticate. The OAuth2 process is explained on the Discord Developer Portal.
After making your request to /oauth2/token with the code, your client id, client secret and redirect uri, you should be getting an access token that you can to authenticate, using the AUTHENTICATE command. Here is what it should look like:
{
"nonce": "5dc0c062-98c6-47a0-8922-bbb52e9d6afa",
"cmd": "AUTHENTICATE",
"args": {
"access_token": "CZhtkLDpNYXgPH9Ml6shqh2OwykChw"
}
}
If the authentication is successful, you should receive a response with evt set to null, application info and user info.
From this point, you are authenticated and you can read messages by using the GET_CHANNEL command to get the last messages, and by subscribing to the MESSAGE_CREATE event to get the new messages when they're sent. Those are documented on the Developer Portal.

Rest service request (>8KB) fails

A Java server exposes REST services using Apache CXF 3.1.10. Trying to call a GET service with a URL longer than 8K, the service gives error.
The REST server uses JAXRSServerFactoryBean that launch a Jetty server. I can not find a way to allow the server to accept request of more than 8K.
Get requests have a query size limit, both on client and server side. (check this for details: maximum length of HTTP GET request?)
Maybe you should move to POST services. Or if you control both the client and server, you may use the request body. (That is allowed for GET requests but there are some clients/servers not supporting that)

Resources