Compare commits
65 Commits
6c623d0149
...
v3.8.5
Author | SHA1 | Date | |
---|---|---|---|
6315169aca | |||
78194a8863 | |||
881eec8e36 | |||
f2092f3649 | |||
f6a019b28d | |||
|
907ef59539 | ||
a4470f3d7f | |||
|
189c5d5b0b | ||
10c29e3693 | |||
|
8d7bbb9689 | ||
dd65abe621 | |||
|
e3bd398a21 | ||
|
d1fcbbeee9 | ||
|
6b3b106b47 | ||
34bcc5f56b | |||
|
ecba261561 | ||
|
491cb18c8d | ||
20a50392ef | |||
|
565184957d | ||
5fec26c32d | |||
|
672019ed07 | ||
758e8007f8 | |||
|
3fc56e126c | ||
3dff223c10 | |||
|
0688ad1464 | ||
4aa0ccb0a0 | |||
|
18136e11b3 | ||
df8925ee12 | |||
|
9da09580b2 | ||
|
e2ce4ee9f4 | ||
|
388c629ac4 | ||
5258bf3cd1 | |||
|
0f3fec0dd1 | ||
628ae8b34b | |||
|
ac4ff557ea | ||
|
e8f05dd422 | ||
|
82231b441a | ||
|
fd7b6574f7 | ||
|
d1697c2394 | ||
|
e9ed74442b | ||
|
3d32a6ef3e | ||
|
9a9ac74333 | ||
3885fd1636 | |||
|
3479604b31 | ||
006188abdc | |||
|
1102b68e52 | ||
|
523e513d70 | ||
|
4eb6354c2b | ||
4a3df192d3 | |||
|
4d7ab0230b | ||
|
d1f2a6f5c2 | ||
|
79dbe98fba | ||
|
6c7607a810 | ||
|
7bfcaa89ce | ||
e03fcc4e4c | |||
|
fa7a4d6630 | ||
c40e700e58 | |||
|
6a3ba94cc9 | ||
|
d6c3176181 | ||
ab68cf6ebd | |||
|
258282b200 | ||
|
82323a8881 | ||
bee64041ab | |||
|
1f56edd316 | ||
|
436a252554 |
2
.github/workflows/autoapprove.yml
vendored
2
.github/workflows/autoapprove.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: approve
|
- name: approve
|
||||||
uses: hmarr/auto-approve-action@v2
|
uses: hmarr/auto-approve-action@v3
|
||||||
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
|
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
|
||||||
id: approve
|
id: approve
|
||||||
with:
|
with:
|
||||||
|
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
@@ -10,13 +10,13 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: setup
|
- name: setup
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.17
|
go-version: 1.17
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: cache
|
- name: cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
@@ -34,7 +34,7 @@ jobs:
|
|||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: lint
|
- name: lint
|
||||||
uses: golangci/golangci-lint-action@v3.1.0
|
uses: golangci/golangci-lint-action@v3.4.0
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||||
|
8
.github/workflows/codeql-analysis.yml
vendored
8
.github/workflows/codeql-analysis.yml
vendored
@@ -45,12 +45,12 @@ jobs:
|
|||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: setup
|
- name: setup
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.17
|
go-version: 1.17
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: init
|
- name: init
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v2
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
@@ -61,7 +61,7 @@ jobs:
|
|||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: autobuild
|
- name: autobuild
|
||||||
uses: github/codeql-action/autobuild@v1
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
@@ -75,4 +75,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: analyze
|
- name: analyze
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/analyze@v2
|
||||||
|
2
.github/workflows/dependabot-automerge.yml
vendored
2
.github/workflows/dependabot-automerge.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: metadata
|
- name: metadata
|
||||||
id: metadata
|
id: metadata
|
||||||
uses: dependabot/fetch-metadata@v1.3.0
|
uses: dependabot/fetch-metadata@v1.3.6
|
||||||
with:
|
with:
|
||||||
github-token: "${{ secrets.TOKEN }}"
|
github-token: "${{ secrets.TOKEN }}"
|
||||||
- name: merge
|
- name: merge
|
||||||
|
6
.github/workflows/pr.yml
vendored
6
.github/workflows/pr.yml
vendored
@@ -10,13 +10,13 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: setup
|
- name: setup
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.17
|
go-version: 1.17
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: cache
|
- name: cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
@@ -34,7 +34,7 @@ jobs:
|
|||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: lint
|
- name: lint
|
||||||
uses: golangci/golangci-lint-action@v3.1.0
|
uses: golangci/golangci-lint-action@v3.4.0
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||||
|
18
go.mod
18
go.mod
@@ -1,14 +1,20 @@
|
|||||||
module go.unistack.org/micro-broker-service/v3
|
module go.unistack.org/micro-broker-service/v3
|
||||||
|
|
||||||
go 1.20
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.23.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
go.unistack.org/micro-server-http/v3 v3.10.13
|
go.unistack.org/micro-server-http/v3 v3.11.31
|
||||||
go.unistack.org/micro/v3 v3.10.18
|
go.unistack.org/micro/v3 v3.10.97
|
||||||
google.golang.org/protobuf v1.30.0
|
google.golang.org/protobuf v1.35.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/go-cmp v0.5.9 // indirect
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
golang.org/x/net v0.8.0 // indirect
|
go.unistack.org/micro-proto/v3 v3.4.1 // indirect
|
||||||
|
golang.org/x/net v0.30.0 // indirect
|
||||||
|
golang.org/x/sys v0.26.0 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
|
||||||
|
google.golang.org/grpc v1.67.1 // indirect
|
||||||
)
|
)
|
||||||
|
46
go.sum
46
go.sum
@@ -2,19 +2,41 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
|
|||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
go.unistack.org/micro-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqtEa9Q=
|
||||||
github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo=
|
||||||
go.unistack.org/micro-server-http/v3 v3.10.13 h1:rt50Hos9hSuyvyYEmw0p5L2eq7HDDz2GpAOUO6M0QC8=
|
go.unistack.org/micro-server-http/v3 v3.10.14 h1:yWeT/Ljag/ueiV6eSK3Xi620b+HzPOgZLCpwx+tQxns=
|
||||||
go.unistack.org/micro-server-http/v3 v3.10.13/go.mod h1:phNG9aosjbneXvZxEVaVQI+NHLLZ3eA82mOH6gGSShY=
|
go.unistack.org/micro-server-http/v3 v3.11.29 h1:IncjMVunK3I4yJ8fIcUjy5ttEVaXskfGb6QXYOV3b5M=
|
||||||
go.unistack.org/micro/v3 v3.10.18 h1:iz193N8eZKGrKPXuX6XMsGIRHMqdvUaZSfb9mzwlUYM=
|
go.unistack.org/micro-server-http/v3 v3.11.29/go.mod h1:GaVKQVMSeHlcBvL2l1kHRxOWuSJ/l+uhUCLHYGidaE0=
|
||||||
go.unistack.org/micro/v3 v3.10.18/go.mod h1:uMAc0U/x7dmtICCrblGf0ZLgYegu3VwQAquu+OFCw1Q=
|
go.unistack.org/micro-server-http/v3 v3.11.31 h1:PVga/ICYj4+8vM7VI82q9/wFBvn/O2zkCzXO6lIbnn8=
|
||||||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
go.unistack.org/micro-server-http/v3 v3.11.31/go.mod h1:3hlTQj3e6HQziJa2Coz/BwvVbt3oRejOevyAPUCuBEk=
|
||||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
go.unistack.org/micro/v3 v3.10.23 h1:4BE7NwwyJbCWOfzjzztamBxJSgRHHW1uQtMGNDLHG3s=
|
||||||
|
go.unistack.org/micro/v3 v3.10.91 h1:vuJY4tXwpqimwIkEJ3TozMYNVQQs+C5QMlQWPgSY/YM=
|
||||||
|
go.unistack.org/micro/v3 v3.10.91/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
|
||||||
|
go.unistack.org/micro/v3 v3.10.97 h1:8l7fv+i06/PjPrBBhRC/ZQkWGIOuHPg3jJN0vktYE78=
|
||||||
|
go.unistack.org/micro/v3 v3.10.97/go.mod h1:YzMldzHN9Ei+zy5t/Psu7RUWDZwUfrNYiStSQtTz90g=
|
||||||
|
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||||
|
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
|
||||||
|
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
|
||||||
|
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
|
||||||
|
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
|
||||||
|
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||||
|
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||||
|
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 h1:X58yt85/IXCx0Y3ZwN6sEIKZzQtDEYaBWrDvErdXrRE=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
|
||||||
|
google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw=
|
||||||
|
google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
|
||||||
|
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
|
||||||
|
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
|
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
|
||||||
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||||
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
|
||||||
|
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
|
25
service.go
25
service.go
@@ -98,8 +98,8 @@ func (b *serviceBroker) Publish(ctx context.Context, topic string, msg *broker.M
|
|||||||
func (b *serviceBroker) publish(ctx context.Context, msgs []*broker.Message, opts ...broker.PublishOption) error {
|
func (b *serviceBroker) publish(ctx context.Context, msgs []*broker.Message, opts ...broker.PublishOption) error {
|
||||||
for _, msg := range msgs {
|
for _, msg := range msgs {
|
||||||
topic, _ := msg.Header.Get(metadata.HeaderTopic)
|
topic, _ := msg.Header.Get(metadata.HeaderTopic)
|
||||||
if logger.V(logger.TraceLevel) {
|
if b.opts.Logger.V(logger.TraceLevel) {
|
||||||
logger.Tracef(ctx, "Publishing to topic %s broker %v", topic, b.addrs)
|
b.opts.Logger.Trace(ctx, fmt.Sprintf("Publishing to topic %s broker %v", topic, b.addrs))
|
||||||
}
|
}
|
||||||
_, err := b.client.Publish(ctx, &pb.PublishRequest{
|
_, err := b.client.Publish(ctx, &pb.PublishRequest{
|
||||||
Topic: topic,
|
Topic: topic,
|
||||||
@@ -122,8 +122,8 @@ func (b *serviceBroker) BatchSubscribe(ctx context.Context, topic string, handle
|
|||||||
|
|
||||||
func (b *serviceBroker) Subscribe(ctx context.Context, topic string, handler broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) {
|
func (b *serviceBroker) Subscribe(ctx context.Context, topic string, handler broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) {
|
||||||
options := broker.NewSubscribeOptions(opts...)
|
options := broker.NewSubscribeOptions(opts...)
|
||||||
if logger.V(logger.TraceLevel) {
|
if b.opts.Logger.V(logger.TraceLevel) {
|
||||||
logger.Tracef(ctx, "Subscribing to topic %s group %s broker %v", topic, options.Group, b.addrs)
|
b.opts.Logger.Trace(ctx, fmt.Sprintf("Subscribing to topic %s group %s broker %v", topic, options.Group, b.addrs))
|
||||||
}
|
}
|
||||||
stream, err := b.client.Subscribe(ctx, &pb.SubscribeRequest{
|
stream, err := b.client.Subscribe(ctx, &pb.SubscribeRequest{
|
||||||
Topic: topic,
|
Topic: topic,
|
||||||
@@ -140,32 +140,33 @@ func (b *serviceBroker) Subscribe(ctx context.Context, topic string, handler bro
|
|||||||
stream: stream,
|
stream: stream,
|
||||||
closed: make(chan bool),
|
closed: make(chan bool),
|
||||||
options: options,
|
options: options,
|
||||||
|
opts: b.opts,
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-sub.closed:
|
case <-sub.closed:
|
||||||
if logger.V(logger.TraceLevel) {
|
if b.opts.Logger.V(logger.TraceLevel) {
|
||||||
logger.Tracef(ctx, "Unsubscribed from topic %s", topic)
|
b.opts.Logger.Trace(ctx, "Unsubscribed from topic %s", topic)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
if logger.V(logger.TraceLevel) {
|
if b.opts.Logger.V(logger.TraceLevel) {
|
||||||
// run the subscriber
|
// run the subscriber
|
||||||
logger.Tracef(ctx, "Streaming from broker %v to topic [%s] group [%s]", b.addrs, topic, options.Group)
|
b.opts.Logger.Trace(ctx, fmt.Sprintf("Streaming from broker %v to topic [%s] group [%s]", b.addrs, topic, options.Group))
|
||||||
}
|
}
|
||||||
if err := sub.run(ctx); err != nil {
|
if err := sub.run(ctx); err != nil {
|
||||||
if logger.V(logger.TraceLevel) {
|
if b.opts.Logger.V(logger.TraceLevel) {
|
||||||
logger.Tracef(ctx, "Resubscribing to topic %s broker %v", topic, b.addrs)
|
b.opts.Logger.Trace(ctx, fmt.Sprintf("Resubscribing to topic %s broker %v", topic, b.addrs))
|
||||||
}
|
}
|
||||||
stream, err := b.client.Subscribe(ctx, &pb.SubscribeRequest{
|
stream, err := b.client.Subscribe(ctx, &pb.SubscribeRequest{
|
||||||
Topic: topic,
|
Topic: topic,
|
||||||
Group: options.Group,
|
Group: options.Group,
|
||||||
}, client.WithAddress(b.addrs...), client.WithRequestTimeout(time.Hour))
|
}, client.WithAddress(b.addrs...), client.WithRequestTimeout(time.Hour))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if logger.V(logger.TraceLevel) {
|
if b.opts.Logger.V(logger.TraceLevel) {
|
||||||
logger.Tracef(ctx, "Failed to resubscribe to topic %s: %v", topic, err)
|
b.opts.Logger.Trace(ctx, fmt.Sprintf("Failed to resubscribe to topic %s: %v", topic, err))
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
continue
|
continue
|
||||||
|
@@ -2,10 +2,12 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
pbmicro "go.unistack.org/micro-broker-service/v3/micro"
|
pbmicro "go.unistack.org/micro-broker-service/v3/micro"
|
||||||
"go.unistack.org/micro/v3/broker"
|
"go.unistack.org/micro/v3/broker"
|
||||||
"go.unistack.org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
type serviceSub struct {
|
type serviceSub struct {
|
||||||
@@ -14,15 +16,21 @@ type serviceSub struct {
|
|||||||
handler broker.Handler
|
handler broker.Handler
|
||||||
stream pbmicro.BrokerService_SubscribeClient
|
stream pbmicro.BrokerService_SubscribeClient
|
||||||
closed chan bool
|
closed chan bool
|
||||||
|
opts broker.Options
|
||||||
options broker.SubscribeOptions
|
options broker.SubscribeOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
type serviceEvent struct {
|
type serviceEvent struct {
|
||||||
|
ctx context.Context
|
||||||
topic string
|
topic string
|
||||||
err error
|
err error
|
||||||
message *broker.Message
|
message *broker.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *serviceEvent) Context() context.Context {
|
||||||
|
return s.ctx
|
||||||
|
}
|
||||||
|
|
||||||
func (s *serviceEvent) Topic() string {
|
func (s *serviceEvent) Topic() string {
|
||||||
return s.topic
|
return s.topic
|
||||||
}
|
}
|
||||||
@@ -67,9 +75,10 @@ func (s *serviceSub) run(ctx context.Context) error {
|
|||||||
for {
|
for {
|
||||||
// TODO: do not fail silently
|
// TODO: do not fail silently
|
||||||
msg, err := s.stream.Recv()
|
msg, err := s.stream.Recv()
|
||||||
|
ctx := metadata.NewIncomingContext(context.Background(), msg.Header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if logger.V(logger.TraceLevel) {
|
if s.opts.Logger.V(logger.TraceLevel) {
|
||||||
logger.Tracef(ctx, "Streaming error for subcription to topic %s: %v", s.Topic(), err)
|
s.opts.Logger.Trace(ctx, fmt.Sprintf("streaming error for subcription to topic %s: %v", s.Topic(), err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// close the exit channel
|
// close the exit channel
|
||||||
@@ -85,6 +94,7 @@ func (s *serviceSub) run(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p := &serviceEvent{
|
p := &serviceEvent{
|
||||||
|
ctx: ctx,
|
||||||
topic: s.topic,
|
topic: s.topic,
|
||||||
message: &broker.Message{
|
message: &broker.Message{
|
||||||
Header: msg.Header,
|
Header: msg.Header,
|
||||||
|
Reference in New Issue
Block a user