Create Subscriber in SimpleQ
Intro
A Subscriber is a FileMaker Script that does three things. It "Listens" for messages that are published to channels it has subscribed to. Sometimes we call it a Listener. Listeners.
- Receives JSON as a script parameter
- Does something with that JSON. This is the custom part that you are going to create.
- Optionally returns a JSON object with an error code if any. If nothing is returned then SimpleQ assumes that there was no error.
It can live in any file that SimpleQ has an external file reference to. In this part of the guide, we are going to step through setting up a Script to be a subscriber and then connecting it to SimpleQ.
We are going to use the SimpleQ_Subscriber_Demo.fmp12 as an example. But you can use any file that you have already connected to SimpleQ.
Review the FileMaker Script
We have already written an example script in the SimpleQ_Subscriber_Demo.fmp12 file. Let's open it and review the comments. The script is called "Receive Greeting". If you are using your own example file you still want to look at the script so you can see what your script needs to do.
Notice that the script
- takes the Script Parameter
- parses the "greeting" out of the JSON
- writes the value of $greeting to a field so we can see it
- and returns a JSON object with a particular format
- See the Reference page for more on this format.
Teach SimpleQ about the subscriber script.
Open up SimpleQ. Navigate to the "Subscribers" Screen using the Navbar on the left. In the middle column, click the Add button
New Subscriber card
Fill out the data in the new Subscriber Card view. The subscriber will connect to the File and the script via their names. This is where you configure those values.
- Subscriber Key is a unique id that you create. We often just use a descriptive name, like "new-order-processor" or "handle-new-greeting"
- Data Source. This is the EXACT name of the External Data Source of the file where the script lives. The exact name, in this case, should SimpleQ_Subscriber_Demo.
- If you need to copy the exact name or if you haven't created an external reference you can click Open Manage Data Sources and do what you need to do.
- Enter the exact script name. In the case of this Guide, the name is "Receive Greeting"
- Click Close.
Done
You are now ready to go on to the next step