Skip to content

Commit 2e09fea

Browse files
authored
Merge pull request #339 from TIBCOSoftware/pubnub-demo
Adding a sample app for PubNub
2 parents 2ec0a8a + 2681206 commit 2e09fea

File tree

17 files changed

+248
-2
lines changed

17 files changed

+248
-2
lines changed

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
_site
22
.sass-cache
33
.jekyll-metadata
4+
public

docs/content/labs/_index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,13 @@ body {
132132
</div>
133133
</div>
134134

135+
<div class="card">
136+
<div class="card-header bg1">
137+
<img class="card-image" src="../images/labs/009-scientific.svg" alt="Share" />
138+
</div>
139+
<div class="card-content">
140+
<p class="card-text">Secure communication using PubNub</p>
141+
<a class="card-start" href="./pubnub-demo" alt="Start">Start!</a>
142+
</div>
143+
</div>
144+

docs/content/labs/kubernetes-demo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Tutorial for Kubernetes
3-
weight: 2540
3+
weight: 2510
44
---
55

66
This demo scneario will help you get up and running with a Flogo demo on Kubernetes. We'll assume you have the following tools installed already. If that is not the case, you might want to install them first. Our [Getting Started](../../../getting-started/getting-started-cli/) guide walks you through the installation of Go, the Flogo CLI and Go Dep

docs/content/labs/pubnub-demo.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
title: Tutorial for PubNub
3+
weight: 2510
4+
---
5+
6+
Building microservices is awesome, having them talk to each other is even more awesome! But in today's world, you can't be too careful when it comes to sending sensitive data across the wire. In this demo you explore how to build a simple microservice to receive the messages from PubNub and write that data to a file.
7+
8+
## What you'll need
9+
### The Flogo Web UI
10+
This demo makes use of the Flogo Web UI. If you don't have that one running yet, please check out [Getting Started with the Flogo Web UI](https://tibcosoftware.github.io/flogo/getting-started/getting-started-webui/)
11+
12+
### A PubNub account
13+
In order to work with PubNub, you'll really need a PubNub account. Luckily, registration is very easy. Go to https://dashboard.pubnub.com/login and use "SIGN UP" to create a new account.
14+
15+
## Step 1: Create an app in PubNub
16+
After signing up, use the big red button to create a new app (the name doesn't matter, and if you want you can change it later too). Now click on the newly created app and you'll see a new KeySet. The Publish and Subscriber key are quite important as they make sure you can connect to your PubNub account.
17+
18+
![](../../images/labs/pubnub-demo/step1.png)
19+
20+
## Step 2: Create an an in the Flogo Web UI
21+
Open the Flogo Web UI and from there, click "New" to create a new microservice and give your new app a name. Click "Create a Flow" to create a new flow and give it any name that you want. Now click on the flow you just created and to open the canvas where you can design your flow.
22+
23+
![](../../images/labs/pubnub-demo/step2.png)
24+
25+
## Step 3: Import a new trigger
26+
Out of the box, Flogo doesn't come with a trigger for PubNub so using the awesome [SDK](https://www.pubnub.com/docs/go/pubnub-go-sdk) provided by the PubNub team we've built one for you! To install that into your Web UI, click on the "+" icon on the left hand side of the screen.
27+
28+
![](../../images/labs/pubnub-demo/step3.png)
29+
30+
From there click on "Install new" and paste "https://github.com/retgits/flogo-components/trigger/pubnubsubscriber" into the input dialog to get this new trigger. After the installation is completed, you can click on "Receive PubNub messages" to add the trigger to your app.
31+
32+
## Step 4: Configuration
33+
The thing we want to store in a file is the message coming from PubNub. To do so, you'll need to create an Input parameter which you can do by clicking on the grey "Input Output" bar on your screen. For example, you can call the parameter "pubnubmessage", keep the type as "string" and click save.
34+
35+
Now it is time to configure the trigger to listen to messages coming from PubNub. To start, click on the trigger and a new dialog will open with a bunch of options. In this dialog you'll have to provide:
36+
37+
* publishKey: The key from PubNub (usually starts with pub-c)
38+
* subscribeKey: The key from PubNub (usually starts with sub-c)
39+
* channel: The channel on which messages will come (totally up to you to choose this)
40+
41+
After that, click on "Map to flow inputs" to map the message from PubNub to the "pubnubmessage" parameter we created earlier. The parameter will already be selected because it is the only one, so the only task left is to click "* message" in the Trigger Output section and "save" to make sure everything is, well…, saved. You can click the little "X" on the top-right (no, not your browser…) to close the dialog window and go back to the flow.
42+
43+
## Step 5: Adding activities
44+
You’ll have to add some acvitivities to the flow for it to do something. In this demo you'll add two activities to the flow. The first activity will log the message and the second one will store the data in a file. To add an activity click on the other large "+" sign
45+
46+
![](../../images/labs/pubnub-demo/step5.png)
47+
48+
On the right-hand side of the screen a list with all the activities the Flogo Web UI knows about will appear. From the list you can pick the "Log Message" activity and click it to make sure it is added to the flow. As you hover over the newly added activity, a cog will appear and as you hover over that thing, a menu will appear to configure your activity. In this window you can configure the inputs of the "Log Message" activity using data from all other activities and triggers in your flow. Right now, we have only the incoming data from PubNub so select "message" in the "Activity Inputs" section and expand the "flow (flow)" section (by clicking on the little black caret) to be able to select the "pubnubmessage".
49+
50+
![](../../images/labs/pubnub-demo/step5a.png)
51+
52+
Now hit the "save" button and we're done with this part!
53+
54+
Now we need to add a new activity to the Flogo Web UI to make sure you can add things to a file. On the main screen of your flow click "Install new activity" to get the same dialog as when installing the trigger.
55+
56+
![](../../images/labs/pubnub-demo/step5b.png)
57+
58+
In the dialog window you can paste "https://github.com/retgits/flogo-components/activity/writetofile". Once the activity is installed you can select it from the list to add it to your flow. Again, hover over the newly added activity and expand the menu to configure your activity. For this activity you'll have to configure all the parameters:
59+
60+
* Append: Should the content be appended to the file or not? In this case we want to, so type "true" in the box
61+
* Content: The content we want to add to the file. In this case it is the message from PubNub again, so expand the "flow (flow)" section (by clicking on the little black caret) and select the "pubnubmessage"
62+
* Create: Should the file be created if it doesn't exist? Well, yes, in this case that is probably a good idea so type "true" in the box
63+
* Filename: The name of the file you want to write the data to. In this case you can call the file whatever you want, like "visitors.txt" (please be sure to add the double quotes as you type in the box)
64+
65+
Click "save" to save the data and return to the main screen of your flow. The completed flow will look like
66+
67+
![](../../images/labs/pubnub-demo/step5c.png)
68+
69+
## Step 6: Build
70+
Those were all the steps needed to design the flow, now let's build an executable from it. On the main screen of your flow click on the "<" button on the top-left hand side of the screen. That will bring you back to your microservice and from here you can select "Build" and choose your operating system of choice. That will tell the Flogo Web UI to go build your microservice and give you a tiny executable in return (about 12mb).
71+
72+
## Step 7: Test
73+
You can run your microservice by either double-clicking it (on Windows) or using a terminal window to run your app (macOS or Linux). If the app started successfully it will give you a message like:
74+
`2018-08-06 21:20:02.867 INFO [engine] - Received status [pubnub.PNConnectedCategory], this is expected for a subscribe, this means there is no error or issue whatsoever`
75+
76+
To test the microservice you can use the PubNub debug console.
77+
78+
![](../../images/labs/pubnub-demo/step7.png)
79+
80+
In the "Default Channel" you'll have to type the same channel name as you configured in your Flogo app (MyChannel, in this example). You can click "ADD CLIENT" to create a new client which will be able to send and receive data. The cool thing that PubNub offers, is that you don't have to open any firewall ports to have the debug console and the microservice talk to each other. At the bottom of the page it will now say "{"text":"Enter Message Here"}", which is the message that you can send to your microservice. Either hit "SEND" or perhaps replace the default message with something like "{"Hello":"World"}". After you click "SEND" the exact message will appear in the window where your microservice is running
81+
82+
![](../../images/labs/pubnub-demo/step7a.png)
83+
84+
And in the log file that was created in the same location as your app
85+
86+
![](../../images/labs/pubnub-demo/step7b.png)

docs/content/labs/serverless.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Tutorial with Serverless Framework
3-
weight: 2550
3+
weight: 2520
44
---
55

66
You can deploy your Flogo apps to, for example, AWS Lambda using the [Serverless Framework](https://serverless.com).With the Serverless Framework, you can configure which events should trigger it, where to deploy it and what kind of resources it is allowed to use without going into the AWS console.
64.9 KB
Loading
3.57 KB
Loading
37.3 KB
Loading
37.7 KB
Loading
27.2 KB
Loading
22.2 KB
Loading
44.2 KB
Loading
62.9 KB
Loading
62.3 KB
Loading
16.7 KB
Loading

samples/pubnub/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# PubNub demo
2+
3+
Security matters, especially when it comes to microservices that handle your information. This demo app uses [PubNub](https://www.pubnub.com/), which provides end-to-end encryption of messages, to reveive messages from a predefined channel
4+
5+
## Building this app
6+
### From the Web UI
7+
To load this app into the Flogo Web UI, you'll need to import two activities first:
8+
9+
* Write To File: https://github.com/retgits/flogo-components/activity/writetofile
10+
* PubNub subscriber: https://github.com/retgits/flogo-components/trigger/pubnubsubscriber
11+
12+
After you've done this, you can upload the `flogo.json` file and update the configuration of the PubNub subscriber to match your PubNub account. Now you can build and run the app.
13+
14+
### From the command line
15+
To get started from the command line, download the `flogo.json` and update the variables for the Publish and Subscriber key, as well as the channel (all of them are set to `xxx`). Now, run `flogo create -f flogo.json pubnubapp` to create a new Flogo app with the name pubnubapp.
16+
17+
To build and run the app, execute
18+
```
19+
cd pubnubapp
20+
flogo build -e
21+
./bin/pubnupapp
22+
```
23+
24+
## More information
25+
If you're looking for a more in-depth overview of how the app is built, check out the [lab](http://tibcosoftware.github.io/flogo/labs/pubnub-demo/)

samples/pubnub/flogo.json

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"name": "PubNubDemoApp",
3+
"type": "flogo:app",
4+
"version": "0.0.1",
5+
"appModel": "1.0.0",
6+
"triggers": [
7+
{
8+
"id": "receive_pub_nub_messages",
9+
"ref": "github.com/retgits/flogo-components/trigger/pubnubsubscriber",
10+
"name": "Receive PubNub Messages",
11+
"description": "PubNub Subscriber",
12+
"settings": {
13+
"publishKey": "xxx",
14+
"subscribeKey": "xxx"
15+
},
16+
"handlers": [
17+
{
18+
"action": {
19+
"ref": "github.com/TIBCOSoftware/flogo-contrib/action/flow",
20+
"data": {
21+
"flowURI": "res://flow:pub_nub_listener"
22+
},
23+
"mappings": {
24+
"input": [
25+
{
26+
"mapTo": "pubnubmessage",
27+
"type": "assign",
28+
"value": "$.message"
29+
}
30+
]
31+
}
32+
},
33+
"settings": {
34+
"channel": "xxx"
35+
}
36+
}
37+
]
38+
}
39+
],
40+
"resources": [
41+
{
42+
"id": "flow:pub_nub_listener",
43+
"data": {
44+
"name": "PubNubListener",
45+
"metadata": {
46+
"input": [
47+
{
48+
"name": "pubnubmessage",
49+
"type": "string"
50+
}
51+
]
52+
},
53+
"tasks": [
54+
{
55+
"id": "log_2",
56+
"name": "Log Message",
57+
"description": "Simple Log Activity",
58+
"activity": {
59+
"ref": "github.com/TIBCOSoftware/flogo-contrib/activity/log",
60+
"input": {
61+
"message": "",
62+
"flowInfo": "false",
63+
"addToFlow": "false"
64+
},
65+
"mappings": {
66+
"input": [
67+
{
68+
"type": "assign",
69+
"value": "$flow.pubnubmessage",
70+
"mapTo": "message"
71+
}
72+
]
73+
}
74+
}
75+
},
76+
{
77+
"id": "writetofile_3",
78+
"name": "Write file",
79+
"description": "Write to a file",
80+
"activity": {
81+
"ref": "github.com/retgits/flogo-components/activity/writetofile",
82+
"input": {
83+
"filename": "",
84+
"content": "",
85+
"append": false,
86+
"create": false
87+
},
88+
"mappings": {
89+
"input": [
90+
{
91+
"type": "literal",
92+
"value": true,
93+
"mapTo": "append"
94+
},
95+
{
96+
"type": "assign",
97+
"value": "$flow.pubnubmessage",
98+
"mapTo": "content"
99+
},
100+
{
101+
"type": "literal",
102+
"value": true,
103+
"mapTo": "create"
104+
},
105+
{
106+
"type": "literal",
107+
"value": "visitors.txt",
108+
"mapTo": "filename"
109+
}
110+
]
111+
}
112+
}
113+
}
114+
],
115+
"links": [
116+
{
117+
"from": "log_2",
118+
"to": "writetofile_3"
119+
}
120+
]
121+
}
122+
}
123+
]
124+
}

0 commit comments

Comments
 (0)