Skip to content

Commit 92e626d

Browse files
authored
Merge pull request #4 from flowable/feat/update_readme_samples
Update README to include basic sample
2 parents 8745aa9 + c40430c commit 92e626d

File tree

1 file changed

+61
-8
lines changed

1 file changed

+61
-8
lines changed

README.md

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ Once locked, the custom logic is responsible for signalling over REST that the w
1010
This project makes implementing such custom logic in Golang easy by implementing the low-level details of the REST API and focus on the actual custom business logic.
1111
Integrations for other languages are also available.
1212

13-
## Authentication
14-
15-
There are default implementations for basic authentication and bearer tokens..
16-
Basic Auth: `flowable.SetAuth("admin", "test")`
17-
Bearer token: `flowable.SetBearerToken("token")`
1813

1914
## Installation
2015

@@ -26,6 +21,14 @@ However, the project is licensed with the Apache 2 license and can be readily cl
2621

2722
## Setup
2823

24+
### Authentication
25+
26+
There are default implementations for basic authentication and bearer tokens..
27+
Basic Auth: `flowable.SetAuth("admin", "test")`
28+
Bearer token: `flowable.SetBearerToken("token")`
29+
30+
### Job Acquisition
31+
2932
The **main.go** file contains the work job acquisition parameters (`acquireParams`). This is where job acquisitions parameters are declared including base url, poll interval, topic name, retry count, task retrieval batch size.
3033

3134

@@ -52,9 +55,7 @@ acquireParams := flowable.AcquireRequest{
5255
go flowable.Subscribe(acquireParams, worker.ExternalWorker)
5356
```
5457

55-
The sample worker business logic is held in `worker/external_worker.go` and supports access to input parameters from the inbound _body_ variable. If any errors were reported from the REST call or parsing of the job, an http _status_ variable will be available — values >= 400 should be considered errors. Handler results support _success_, _fail_, _bpmnError_ and _cmmnTerminate_ responses.
56-
57-
## Logging
58+
### Logging
5859

5960
- **Default:** logging is enabled by default.
6061
- **Control:** toggle logging at runtime from `main.go` using:
@@ -66,6 +67,58 @@ flowable.SetEnableLogging(false) // disable
6667

6768
When logging is disabled the library will suppress internal `log.Printf` messages.
6869

70+
## Samples
71+
72+
```
73+
package main
74+
75+
import (
76+
"time"
77+
"log"
78+
"github.com/flowable/flowable-external-client-golang/flowable"
79+
)
80+
81+
func ExternalWorker(status int, body string) (flowable.HandlerStatus, *flowable.HandlerResult) {
82+
83+
// Initialize return status
84+
85+
res := &flowable.HandlerResult{
86+
Status: flowable.HandlerSuccess,
87+
WorkerId: "",
88+
Variables: []flowable.HandlerVariable{},
89+
ErrorCode: "",
90+
}
91+
92+
log.Printf("CustomWorker: processed job.")
93+
res.Status = flowable.HandlerSuccess
94+
return res.Status, res
95+
}
96+
97+
func main() {
98+
99+
flowable.SetAuth("admin", "test")
100+
acquireParams := flowable.AcquireRequest{
101+
Topic: "testing",
102+
LockDuration: "PT10M",
103+
NumberOfTasks: 1,
104+
NumberOfRetries: 5,
105+
WorkerId: "worker1",
106+
ScopeType: "bpmn",
107+
URL: "http://localhost:8090",
108+
Interval: 10 * time.Second,
109+
}
110+
111+
go flowable.Subscribe(acquireParams, ExternalWorker)
112+
113+
// Ennsure application keeps running..
114+
select {}
115+
}
116+
```
117+
118+
A more complete sample worker can be found in `worker/external_worker.go` and supports access to input parameters from the inbound _body_ variable. If any errors were reported from the REST call or parsing of the job, an http _status_ variable will be available — values >= 400 should be considered errors. Handler results support _success_, _fail_, _bpmnError_ and _cmmnTerminate_ responses.
119+
120+
121+
69122
## Integration Tests With Cached HTTP Cassettes
70123

71124
Integration tests in `test/flowable_integration_test.go` use a VCR-style recorder (`go-vcr`) and store HTTP cassettes in `test/fixtures/cassettes`.

0 commit comments

Comments
 (0)