-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support message poll rest endpoint * replace mongo install action in the github actions * returns 204 no-content if the message list is empty
- Loading branch information
Showing
11 changed files
with
279 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,9 @@ jobs: | |
build_test: | ||
name: build and test | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
mongodb-version: [4.2] | ||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v1 | ||
|
@@ -51,16 +54,13 @@ jobs: | |
with: | ||
fetch-depth: 1 | ||
path: go/src/github.com/kafkaesque-io/pulsar-beam | ||
- name: Install MongoDB | ||
run: | | ||
echo $GITHUB_EVENT_NAME | ||
echo $GITHUB_EVENT_PATH | ||
sudo apt-get update | ||
sudo apt-get install -y mongodb | ||
- name: Start MongoDB v${{ matrix.mongodb-version }} | ||
uses: supercharge/[email protected] | ||
with: | ||
mongodb-version: ${{ matrix.mongodb-version }} | ||
- name: Verify MongoDB Installation and Status | ||
run: | | ||
ls /var/lib/mongodb | ||
sudo systemctl status mongodb | ||
sudo docker ps | ||
- name: Build Binary | ||
run: | | ||
go mod download | ||
|
@@ -111,7 +111,10 @@ jobs: | |
e2e_test: | ||
name: e2e_test | ||
needs: [analysis, build_test] | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
mongodb-version: [4.2] | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v1 | ||
|
@@ -123,16 +126,13 @@ jobs: | |
run: | | ||
pwd | ||
go mod download | ||
- name: Install MongoDB | ||
run: | | ||
echo $GITHUB_EVENT_NAME | ||
echo $GITHUB_EVENT_PATH | ||
sudo apt-get update | ||
sudo apt-get install -y mongodb | ||
- name: Start MongoDB v${{ matrix.mongodb-version }} | ||
uses: supercharge/[email protected] | ||
with: | ||
mongodb-version: ${{ matrix.mongodb-version }} | ||
- name: Verify MongoDB Installation and Status | ||
run: | | ||
ls /var/lib/mongodb | ||
sudo systemctl status mongodb | ||
sudo docker ps | ||
- name: Set up root certificate | ||
env: | ||
PULSAR_CLIENT_CERT: ${{ secrets.PULSAR_CLIENT_CERT }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ Beam is an http based streaming and queueing system backed up by Apache Pulsar. | |
- [x] A message can be pushed to a webhook or Cloud Function for consumption. | ||
- [x] A webhook or Cloud Function receives a message, process it and reply another message, in a response body, back to another Pulsar topic via Pulsar Beam. | ||
- [x] Messages can be streamed via HTTP Sever Sent Event, [SSE](https://www.html5rocks.com/en/tutorials/eventsource/basics/) | ||
- [x] Support HTTP polling of batch messages | ||
|
||
Opening an issue and PR are welcomed! Please email `[email protected]` for any inquiry or demo. | ||
|
||
|
@@ -59,6 +60,21 @@ Query parameters | |
2. SubscriptionInitialPosition -> supported type are `latest` as default and `earliest` | ||
3. SubscriptionName -> the length must be 5 characters or longer. An auto-generated name will be provided in absence. Only the auto-generated subscription will be unsubscribed. | ||
|
||
### Endpoint to poll batch messages | ||
Polls a batch of messages always from the earliest subscription position from a topic. | ||
``` | ||
/v2/poll/{persistent}/{tenant}/{namespace}/{topic} | ||
``` | ||
These HTTP headers may be required to map to Pulsar topic. | ||
1. Authorization -> Bearer token as Pulsar token | ||
2. PulsarUrl -> *optional* a fully qualified pulsar or pulsar+ssl URL where the message should be sent to. It is optional. The message will be sent to Pulsar URL specified under `PulsarBrokerURL` in the pulsar-beam.yml file if it is absent. | ||
|
||
Query parameters | ||
1. SubscriptionType -> Supported type strings are `exclusive` as default, `shared`, and `failover` | ||
2. SubscriptionName -> the length must be 5 characters or longer. An auto-generated name will be provided in absence. Only the auto-generated subscription will be unsubscribed. | ||
3. size -> The batch size. The default is 10. | ||
4. perMessageTimeoutMs -> is a wait time out for the next message to arrive. It is in milliseconds per message. The default is 300ms. | ||
|
||
### Webhook registration | ||
Webhook registration is done via REST API backed by a database of your choice, such as MongoDB, in momery cache, and Pulsar itself. Yes, you can use a compacted Pulsar topic as a database table to perform CRUD. The configuration parameter is `"PbDbType": "inmemory",` in the `pulsar_beam.yml` file or the env variable `PbDbType`. | ||
|
||
|
@@ -149,7 +165,7 @@ One end to end test is under `./src/e2e/e2etest.go`, that performs the following | |
4. Verify the replied message on the sink topic | ||
5. Delete the topic and its webhook document via RESTful API | ||
|
||
Since the set up is non-trivial involving Pulsar Beam, a Cloud function or webhook, the test tool, and Pulsar itself with SSL, we recommend to take advantage of [the free plan at Kafkaesque.io](https://kafkaesque.io) as the Pulsar server and a Cloud Function that we have verified GCP Fcuntion, Azure Function or AWS Lambda will suffice in the e2e flow. | ||
Since the set up is non-trivial involving Pulsar Beam, a Cloud function or webhook, the test tool, and Pulsar itself with SSL, we recommend to take advantage of [the free plan at kesque.com](https://kesque.com) as the Pulsar server and a Cloud Function that we have verified GCP Fcuntion, Azure Function or AWS Lambda will suffice in the e2e flow. | ||
|
||
Step to perform unit test | ||
```bash | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package model | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/apache/pulsar-client-go/pulsar" | ||
) | ||
|
||
// PulsarMessage is the Pulsar Message type | ||
type PulsarMessage struct { | ||
Payload []byte `json:"payload"` | ||
Topic string `json:"topic"` | ||
EventTime time.Time `json:"eventTime"` | ||
PublishTime time.Time `json:"publishTime"` | ||
MessageID string `json:"messageId"` | ||
Key string `json:"key"` | ||
} | ||
|
||
// PulsarMessages encapsulates a list of messages to be returned to a client | ||
type PulsarMessages struct { | ||
Limit int `json:"limit"` | ||
Size int `json:"size"` | ||
Messages []PulsarMessage `json:"messages"` | ||
} | ||
|
||
// NewPulsarMessages create a PulsarMessages object | ||
func NewPulsarMessages(initSize int) PulsarMessages { | ||
return PulsarMessages{ | ||
Limit: initSize, | ||
Size: 0, | ||
Messages: make([]PulsarMessage, 0), | ||
} | ||
} | ||
|
||
// AddPulsarMessage adds a Pulsar Message to the payload, return true if reaches capacity | ||
func (msgs *PulsarMessages) AddPulsarMessage(msg pulsar.Message) bool { | ||
if msgs.Size >= msgs.Limit { | ||
return true | ||
} | ||
msgs.Messages = append(msgs.Messages, PulsarMessage{ | ||
Payload: msg.Payload(), | ||
Topic: msg.Topic(), | ||
EventTime: msg.EventTime(), | ||
PublishTime: msg.PublishTime(), | ||
MessageID: fmt.Sprintf("%+v", msg.ID()), | ||
Key: msg.Key(), | ||
}) | ||
msgs.Size++ | ||
|
||
return msgs.Size >= msgs.Limit | ||
} | ||
|
||
// IsEmpty checks if the message list is empty | ||
func (msgs *PulsarMessages) IsEmpty() bool { | ||
return msgs.Size == 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/kafkaesque-io/pulsar-beam/src/model" | ||
) | ||
|
||
func TestPulsarMessages(t *testing.T) { | ||
|
||
messages := NewPulsarMessages(10) | ||
equals(t, messages.Limit, 10) | ||
equals(t, messages.IsEmpty(), true) | ||
} |
Oops, something went wrong.