Skip to content

A simple and tiny Salesforce platform event monitor using node.js based on Faye module. Use this if you don't want to install another bloated AppEx app when you just want to see and check if PE are working/fired as expected.

Notifications You must be signed in to change notification settings

bhuone-garbu/sf-event-monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Salesforce platform event monitoring script (node.js)

UPDATE!

I built this in the early 2018 when Salesforce started pushing for streaming and platform events for integrating with external 3rd party clients instead of custom point-to-point solution. 'High volume' was not even a thing nor the 'Publish After Commit' feature and everything was pretty much experimental, which meant monitoring and debugging events was a nightmare and had to rely on system built by someone else.

Soon people started building and installing app exchange packages with UIs to monitor events. However, the whole idea of installing external 3rd party bloatware app exchange packages just to see some events was kind of cumbersome to me. Being a developer, I could not help but write a simple subscriber myself that allows me to test platform events and tweak it exactly how I want when necessary to integrate in other system.

It's generic and anyone can run and monitoring the events straight from their command line using node. How much useful this is now - I will leave this up to the readers/developers. I am sure there are more better tools out there now. Thanks for stopping by.

Intro

This is just a simple dumb script I created to monitor the platform events published by Salesforce using node. When a message is received, I simply print the message on the screen. That's it.

This is just for monitoring purpose using the Faye node module: https://faye.jcoglan.com/

Getting started

Checkout (clone) this repo. Assuming npm and node are installed, run the following:

npm install

Create an .env file at the root of the root of the project with the following details:

CLIENT_ID="client_id"
CLIENT_SECRET="client_secret"
USERNAME="your sf username based on the sandbox or live environment"
PASSWORD="your sf password"

Ensure that your user can authenticate and has permissin to read the specific Platform Event that you want to monitor.

Running the cli

Pass the name of the platform event that exists on Salesforce that you want to monitor as named argument: --event=Hello__e

Additionally, for monitoring on live environment, provide the NODE_ENV variable as login

NODE_ENV=login node sf_subscriber.js --event='Hello__e'

Or it will default to test/dev sandbox

node sf_subscriber.js --event='Hello__e'

This can always be hardcorded on the .env file if needed.

All this is doing is switching prefix of the global oauth2 endpoint on Salesforce

  • https://test.salesforce.com/services/oauth2/token for sandbox/uat environment
  • https://login.salesforce.com/services/oauth2/token for production salesforce

Assuming everything works fine, then you should see that you have subscribed and start receiving message

$ node sf_subscriber.js --event='Hello__e'

Salesforce instance url: https://some_instance.salesforce.com
Subscribed to: Hello__e
Message:

{"schema":"-2QuiBn9MjLlv6RCsJrA5Q", "body" : "hello" }

About

A simple and tiny Salesforce platform event monitor using node.js based on Faye module. Use this if you don't want to install another bloated AppEx app when you just want to see and check if PE are working/fired as expected.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published