Skip to content

Commit 033ffd8

Browse files
authored
add smart publish to (#53)
Add direct connection
1 parent 3356a45 commit 033ffd8

File tree

25 files changed

+765
-310
lines changed

25 files changed

+765
-310
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ main ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ main ]
20+
schedule:
21+
- cron: '0 0 * * 0'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
language: [ 'go' ]
32+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
33+
# Learn more:
34+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v2
39+
40+
# Initializes the CodeQL tools for scanning.
41+
- name: Initialize CodeQL
42+
uses: github/codeql-action/init@v1
43+
with:
44+
languages: ${{ matrix.language }}
45+
# If you wish to specify custom queries, you can do so here or in a config file.
46+
# By default, queries listed here will override any specified in a config file.
47+
# Prefix the list here with "+" to use these queries and those in the config file.
48+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
49+
50+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
51+
# If this step fails, then you should remove it and run the build manually (see below)
52+
- name: Autobuild
53+
uses: github/codeql-action/autobuild@v1
54+
55+
# ℹ️ Command-line programs to run using the OS shell.
56+
# 📚 https://git.io/JvXDl
57+
58+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
59+
# and modify them (or add more) to build your code if your project
60+
# uses a compiled language
61+
62+
#- run: |
63+
# make bootstrap
64+
# make release
65+
66+
- name: Perform CodeQL Analysis
67+
uses: github/codeql-action/analyze@v1

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ check: $(STATICCHECK)
2323
$(STATICCHECK) ./pkg/stream
2424

2525
test: vet fmt check
26-
go test -v ./pkg/stream -race -coverprofile=coverage.txt -covermode=atomic -tags debug
26+
go test -v ./pkg/stream -race -coverprofile=coverage.txt -covermode=atomic -tags debug #-ginkgo.v
2727

2828
integration-test: vet fmt check
2929
cd ./pkg/system_integration && go test -v . -race -coverprofile=coverage.txt -covermode=atomic -tags debug -timeout 99999s

README.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,18 @@ go run perfTest/perftest.go silent
3838
---
3939

4040
The API are composed by mandatory and optional arguments.
41-
The optional be set in the standard go way as:
41+
To set the optional parameters you can use builders:
4242

43+
```golang
44+
env, err := stream.NewEnvironment(
45+
stream.NewEnvironmentOptions().
46+
SetHost("localhost").
47+
SetPort(5552).
48+
SetUser("guest").
49+
SetPassword("guest"))
50+
```
51+
52+
or standard way:
4353
```golang
4454
env, err := stream.NewEnvironment(
4555
&stream.EnvironmentOptions{
@@ -55,26 +65,13 @@ env, err := stream.NewEnvironment(
5565
)
5666
```
5767

58-
or using builders ( the suggested way):
59-
60-
```golang
61-
env, err := stream.NewEnvironment(
62-
stream.NewEnvironmentOptions().
63-
SetHost("localhost").
64-
SetPort(5552).
65-
SetUser("guest").
66-
SetPassword("guest"))
67-
```
6868

6969
`nil` is also a valid value, default values will be provided:
7070

7171
```golang
7272
env, err := stream.NewEnvironment(nil)
7373
```
7474

75-
The suggested way is to use builders.
76-
77-
7875
### Build from source
7976
---
8077

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7-alpha
1+
0.8-alpha

examples/getting_started.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ func main() {
8585
chPublishConfirm := producer.NotifyPublishConfirmation()
8686
handlePublishConfirm(chPublishConfirm)
8787

88-
// each publish sends a number of messages, the batchMessages should be around 100 messages for send
89-
for i := 0; i < 2; i++ {
90-
_, err := producer.BatchPublish(CreateArrayMessagesForTesting(10))
88+
// the send method automatically aggregates the messages
89+
// based on batch size
90+
for i := 0; i < 1000; i++ {
91+
err := producer.Send(amqp.NewMessage([]byte("hello_world_" + strconv.Itoa(i))))
9192
CheckErr(err)
9293
}
9394

examples/haProducer/http/http.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package http
2+
3+
import (
4+
"encoding/json"
5+
"github.com/pkg/errors"
6+
"io/ioutil"
7+
"net/http"
8+
"strconv"
9+
)
10+
11+
type queue struct {
12+
Messages int `json:"messages"`
13+
}
14+
15+
type connection struct {
16+
Name string `json:"name"`
17+
}
18+
19+
func messagesReady(queueName string, port string) (int, error) {
20+
bodyString, err := httpGet("http://localhost:"+port+"/api/queues/%2F/"+queueName, "guest", "guest")
21+
if err != nil {
22+
return 0, err
23+
}
24+
25+
var data queue
26+
err = json.Unmarshal([]byte(bodyString), &data)
27+
if err != nil {
28+
return 0, err
29+
}
30+
return data.Messages, nil
31+
}
32+
33+
func Connections(port string) ([]connection, error) {
34+
bodyString, err := httpGet("http://localhost:"+port+"/api/connections/", "guest", "guest")
35+
if err != nil {
36+
return nil, err
37+
}
38+
39+
var data []connection
40+
err = json.Unmarshal([]byte(bodyString), &data)
41+
if err != nil {
42+
return nil, err
43+
}
44+
return data, nil
45+
}
46+
47+
func DropConnection(name string, port string) error {
48+
_, err := httpDelete("http://localhost:"+port+"/api/connections/"+name, "guest", "guest")
49+
if err != nil {
50+
return err
51+
}
52+
53+
return nil
54+
}
55+
func httpGet(url, username, password string) (string, error) {
56+
return baseCall(url, username, password, "GET")
57+
}
58+
59+
func httpDelete(url, username, password string) (string, error) {
60+
return baseCall(url, username, password, "DELETE")
61+
}
62+
63+
func baseCall(url, username, password string, method string) (string, error) {
64+
var client http.Client
65+
req, err := http.NewRequest(method, url, nil)
66+
if err != nil {
67+
return "", err
68+
}
69+
req.SetBasicAuth(username, password)
70+
71+
resp, err3 := client.Do(req)
72+
73+
if err3 != nil {
74+
return "", err3
75+
}
76+
77+
defer resp.Body.Close()
78+
79+
if resp.StatusCode == 200 { // OK
80+
bodyBytes, err2 := ioutil.ReadAll(resp.Body)
81+
if err2 != nil {
82+
return "", err2
83+
}
84+
return string(bodyBytes), nil
85+
86+
}
87+
return "", errors.New(strconv.Itoa(resp.StatusCode))
88+
89+
}

0 commit comments

Comments
 (0)