Compare commits
151 Commits
upstream
...
dependabot
Author | SHA1 | Date | |
---|---|---|---|
|
b23f3e7cec | ||
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 | ||
b55618f9ff | |||
3a962deb77 | |||
|
3c9a299382 | ||
|
e0ecd04406 | ||
|
0d8e7533e8 | ||
ac0ec269a4 | |||
|
a1a10b1683 | ||
0b8193410f | |||
|
6ba3b3af79 | ||
07795680b8 | |||
|
206d8634a4 | ||
895c3ddb87 | |||
|
d4c42b3a8e | ||
5ce9eb0e1f | |||
|
8dc3458317 | ||
4c2499445b | |||
|
6937c892e7 | ||
4a2e1f5f10 | |||
|
3883c269e4 | ||
|
4a2e6c2168 | ||
e9b5d83a57 | |||
|
435619f634 | ||
|
827de006d0 | ||
26e847ad5f | |||
|
61ca301795 | ||
7cdaf9a303 | |||
|
3635367fc7 | ||
801ac76779 | |||
|
648a1b4d16 | ||
|
efc8cf8efb | ||
2d99a07ba7 | |||
e5ea846039 | |||
7ca3e5d7c8 | |||
|
27366fcd1d | ||
|
c16984b761 | ||
45dc57c27c | |||
|
9ca9c827e5 | ||
30801249ae | |||
8b8bb7d3d4 | |||
|
822ea84067 | ||
22c48f4b90 | |||
|
4567bc705a | ||
|
9985962a9d | ||
|
09a4e24e7b | ||
|
e271d94ebf | ||
|
0921a48e97 | ||
|
3f42b45aac | ||
|
31a919b8d4 | ||
|
4cdef63a96 | ||
|
ac0ef079c0 | ||
|
d19cbb468f | ||
|
4896bd9cc3 | ||
|
51b20b9f2e | ||
|
795efe0352 | ||
|
70da131fad | ||
|
1a3a4d0ae4 | ||
55d1d81f04 | |||
89d804f9e6 | |||
|
6998184d9e | ||
|
dd3665cef5 | ||
dd51dad2e0 | |||
d8871e07ee | |||
|
585eff3652 | ||
|
e9b89a287e | ||
|
abd88c183b | ||
|
1b00ec8807 | ||
|
da02e5860d | ||
|
64994e5bda | ||
|
f7d473e2c5 | ||
|
2dd5557735 | ||
|
aa4553ee10 | ||
|
413059aac2 | ||
78eac5bec5 | |||
|
cd7af99f59 | ||
|
e180d0df40 | ||
6b43ea718d | |||
75fdff84be | |||
4c38d086af | |||
13e50e7a01 | |||
b5ced1501c | |||
|
f3abef0589 | ||
0a518438aa | |||
|
d7eb48a30d | ||
|
657f166718 | ||
|
3f803431b9 | ||
4491ec1af7 | |||
|
8c206313b6 | ||
c60040633c | |||
f95d343393 |
24
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
24
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: For reporting bugs in go-micro
|
||||
title: "[BUG]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
|
||||
1. What are you trying to do?
|
||||
2. What did you expect to happen?
|
||||
3. What happens instead?
|
||||
|
||||
**How to reproduce the bug:**
|
||||
|
||||
If possible, please include a minimal code snippet here.
|
||||
|
||||
**Environment:**
|
||||
Go Version: please paste `go version` output here
|
||||
```
|
||||
please paste `go env` output here
|
||||
```
|
17
.github/ISSUE_TEMPLATE/feature-request---enhancement.md
vendored
Normal file
17
.github/ISSUE_TEMPLATE/feature-request---enhancement.md
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Feature request / Enhancement
|
||||
about: If you have a need not served by go-micro
|
||||
title: "[FEATURE]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
14
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
14
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
name: Question
|
||||
about: Ask a question about go-micro
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Before asking, please check if your question has already been answered:
|
||||
|
||||
1. Check the documentation - https://micro.mu/docs/
|
||||
2. Check the examples and plugins - https://github.com/micro/examples & https://github.com/micro/go-plugins
|
||||
3. Search existing issues
|
9
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
9
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
## Pull Request template
|
||||
Please, go through these steps before clicking submit on this PR.
|
||||
|
||||
1. Give a descriptive title to your PR.
|
||||
2. Provide a description of your changes.
|
||||
3. Make sure you have some relevant tests.
|
||||
4. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if applicable).
|
||||
|
||||
**PLEASE REMOVE THIS TEMPLATE BEFORE SUBMITTING**
|
19
.github/dependabot.yml
vendored
Normal file
19
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
# Maintain dependencies for GitHub Actions
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
|
||||
# Maintain dependencies for Golang
|
||||
- package-ecosystem: "gomod"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
20
.github/workflows/autoapprove.yml
vendored
Normal file
20
.github/workflows/autoapprove.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: "autoapprove"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
autoapprove:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: approve
|
||||
uses: hmarr/auto-approve-action@v3
|
||||
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
|
||||
id: approve
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
21
.github/workflows/automerge.yml
vendored
Normal file
21
.github/workflows/automerge.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
name: "automerge"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'vtolstov'
|
||||
steps:
|
||||
- name: merge
|
||||
id: merge
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
47
.github/workflows/build.yml
vendored
Normal file
47
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
name: build
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.17
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: ${{ runner.os }}-go-
|
||||
- name: deps
|
||||
run: go get -v -t -d ./...
|
||||
- name: test
|
||||
env:
|
||||
INTEGRATION_TESTS: yes
|
||||
run: go test -mod readonly -v ./...
|
||||
lint:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v3.4.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.30
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# args: --issues-exit-code=0
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
78
.github/workflows/codeql-analysis.yml
vendored
Normal file
78
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "codeql"
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["prbuild"]
|
||||
types:
|
||||
- completed
|
||||
push:
|
||||
branches: [ master, v3 ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master, v3 ]
|
||||
schedule:
|
||||
- cron: '34 1 * * 0'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'go' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# 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
|
||||
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: setup
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.17
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: init
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# 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)
|
||||
- name: autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: analyze
|
||||
uses: github/codeql-action/analyze@v2
|
27
.github/workflows/dependabot-automerge.yml
vendored
Normal file
27
.github/workflows/dependabot-automerge.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
name: "dependabot-automerge"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
steps:
|
||||
- name: metadata
|
||||
id: metadata
|
||||
uses: dependabot/fetch-metadata@v1.3.6
|
||||
with:
|
||||
github-token: "${{ secrets.TOKEN }}"
|
||||
- name: merge
|
||||
id: merge
|
||||
if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
47
.github/workflows/pr.yml
vendored
Normal file
47
.github/workflows/pr.yml
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
name: prbuild
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.17
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: ${{ runner.os }}-go-
|
||||
- name: deps
|
||||
run: go get -v -t -d ./...
|
||||
- name: test
|
||||
env:
|
||||
INTEGRATION_TESTS: yes
|
||||
run: go test -mod readonly -v ./...
|
||||
lint:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v3.4.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.30
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# args: --issues-exit-code=0
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
191
LICENSE
Normal file
191
LICENSE
Normal file
@@ -0,0 +1,191 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Copyright 2020 Unistack LLC.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
3
generate.go
Normal file
3
generate.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package service
|
||||
|
||||
//go:generate protoc -I./proto -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --go-micro_out=components=micro|rpc,standalone=true,paths=source_relative:./micro proto/broker.proto
|
12
go.mod
12
go.mod
@@ -1,7 +1,9 @@
|
||||
module github.com/micro/go-plugins/broker/service/v2
|
||||
module go.unistack.org/micro-broker-service/v3
|
||||
|
||||
go 1.13
|
||||
go 1.16
|
||||
|
||||
require github.com/micro/go-micro/v2 v2.9.1-0.20200716153311-f9bf56239306
|
||||
|
||||
replace github.com/coreos/etcd => github.com/ozonru/etcd v3.3.20-grpc1.27-origmodule+incompatible
|
||||
require (
|
||||
go.unistack.org/micro/v3 v3.10.11
|
||||
google.golang.org/grpc v1.53.0
|
||||
google.golang.org/protobuf v1.28.1
|
||||
)
|
||||
|
68
micro/broker_micro.pb.go
Normal file
68
micro/broker_micro.pb.go
Normal file
@@ -0,0 +1,68 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// protoc-gen-go-micro version: v3.5.3
|
||||
// source: broker.proto
|
||||
|
||||
package servicepb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
proto "go.unistack.org/micro-broker-service/v3/proto"
|
||||
api "go.unistack.org/micro/v3/api"
|
||||
client "go.unistack.org/micro/v3/client"
|
||||
)
|
||||
|
||||
var (
|
||||
BrokerServiceName = "BrokerService"
|
||||
|
||||
BrokerServiceEndpoints = []api.Endpoint{}
|
||||
)
|
||||
|
||||
func NewBrokerServiceEndpoints() []api.Endpoint {
|
||||
return BrokerServiceEndpoints
|
||||
}
|
||||
|
||||
type BrokerServiceClient interface {
|
||||
Publish(ctx context.Context, req *proto.PublishRequest, opts ...client.CallOption) (*proto.PublishResponse, error)
|
||||
BatchPublish(ctx context.Context, req *proto.BatchPublishRequest, opts ...client.CallOption) (*proto.BatchPublishResponse, error)
|
||||
Subscribe(ctx context.Context, req *proto.SubscribeRequest, opts ...client.CallOption) (BrokerService_SubscribeClient, error)
|
||||
BatchSubscribe(ctx context.Context, req *proto.BatchSubscribeRequest, opts ...client.CallOption) (BrokerService_BatchSubscribeClient, error)
|
||||
}
|
||||
|
||||
type BrokerService_SubscribeClient interface {
|
||||
Context() context.Context
|
||||
SendMsg(msg interface{}) error
|
||||
RecvMsg(msg interface{}) error
|
||||
Close() error
|
||||
Recv() (*proto.Message, error)
|
||||
}
|
||||
|
||||
type BrokerService_BatchSubscribeClient interface {
|
||||
Context() context.Context
|
||||
SendMsg(msg interface{}) error
|
||||
RecvMsg(msg interface{}) error
|
||||
Close() error
|
||||
Recv() (*proto.Message, error)
|
||||
}
|
||||
|
||||
type BrokerServiceServer interface {
|
||||
Publish(ctx context.Context, req *proto.PublishRequest, rsp *proto.PublishResponse) error
|
||||
BatchPublish(ctx context.Context, req *proto.BatchPublishRequest, rsp *proto.BatchPublishResponse) error
|
||||
Subscribe(ctx context.Context, req *proto.SubscribeRequest, stream BrokerService_SubscribeStream) error
|
||||
BatchSubscribe(ctx context.Context, req *proto.BatchSubscribeRequest, stream BrokerService_BatchSubscribeStream) error
|
||||
}
|
||||
|
||||
type BrokerService_SubscribeStream interface {
|
||||
Context() context.Context
|
||||
SendMsg(msg interface{}) error
|
||||
RecvMsg(msg interface{}) error
|
||||
Close() error
|
||||
Send(msg *proto.Message) error
|
||||
}
|
||||
|
||||
type BrokerService_BatchSubscribeStream interface {
|
||||
Context() context.Context
|
||||
SendMsg(msg interface{}) error
|
||||
RecvMsg(msg interface{}) error
|
||||
Close() error
|
||||
Send(msg *proto.Message) error
|
||||
}
|
212
micro/broker_micro_rpc.pb.go
Normal file
212
micro/broker_micro_rpc.pb.go
Normal file
@@ -0,0 +1,212 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// protoc-gen-go-micro version: v3.5.3
|
||||
// source: broker.proto
|
||||
|
||||
package servicepb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
proto "go.unistack.org/micro-broker-service/v3/proto"
|
||||
api "go.unistack.org/micro/v3/api"
|
||||
client "go.unistack.org/micro/v3/client"
|
||||
server "go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
type brokerServiceClient struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewBrokerServiceClient(name string, c client.Client) BrokerServiceClient {
|
||||
return &brokerServiceClient{c: c, name: name}
|
||||
}
|
||||
|
||||
func (c *brokerServiceClient) Publish(ctx context.Context, req *proto.PublishRequest, opts ...client.CallOption) (*proto.PublishResponse, error) {
|
||||
rsp := &proto.PublishResponse{}
|
||||
err := c.c.Call(ctx, c.c.NewRequest(c.name, "BrokerService.Publish", req), rsp, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
func (c *brokerServiceClient) BatchPublish(ctx context.Context, req *proto.BatchPublishRequest, opts ...client.CallOption) (*proto.BatchPublishResponse, error) {
|
||||
rsp := &proto.BatchPublishResponse{}
|
||||
err := c.c.Call(ctx, c.c.NewRequest(c.name, "BrokerService.BatchPublish", req), rsp, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
func (c *brokerServiceClient) Subscribe(ctx context.Context, req *proto.SubscribeRequest, opts ...client.CallOption) (BrokerService_SubscribeClient, error) {
|
||||
stream, err := c.c.Stream(ctx, c.c.NewRequest(c.name, "BrokerService.Subscribe", &proto.SubscribeRequest{}), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := stream.Send(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &brokerServiceClientSubscribe{stream}, nil
|
||||
}
|
||||
|
||||
type brokerServiceClientSubscribe struct {
|
||||
stream client.Stream
|
||||
}
|
||||
|
||||
func (s *brokerServiceClientSubscribe) Close() error {
|
||||
return s.stream.Close()
|
||||
}
|
||||
|
||||
func (s *brokerServiceClientSubscribe) Context() context.Context {
|
||||
return s.stream.Context()
|
||||
}
|
||||
|
||||
func (s *brokerServiceClientSubscribe) SendMsg(msg interface{}) error {
|
||||
return s.stream.Send(msg)
|
||||
}
|
||||
|
||||
func (s *brokerServiceClientSubscribe) RecvMsg(msg interface{}) error {
|
||||
return s.stream.Recv(msg)
|
||||
}
|
||||
|
||||
func (s *brokerServiceClientSubscribe) Recv() (*proto.Message, error) {
|
||||
msg := &proto.Message{}
|
||||
if err := s.stream.Recv(msg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
func (c *brokerServiceClient) BatchSubscribe(ctx context.Context, req *proto.BatchSubscribeRequest, opts ...client.CallOption) (BrokerService_BatchSubscribeClient, error) {
|
||||
stream, err := c.c.Stream(ctx, c.c.NewRequest(c.name, "BrokerService.BatchSubscribe", &proto.BatchSubscribeRequest{}), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := stream.Send(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &brokerServiceClientBatchSubscribe{stream}, nil
|
||||
}
|
||||
|
||||
type brokerServiceClientBatchSubscribe struct {
|
||||
stream client.Stream
|
||||
}
|
||||
|
||||
func (s *brokerServiceClientBatchSubscribe) Close() error {
|
||||
return s.stream.Close()
|
||||
}
|
||||
|
||||
func (s *brokerServiceClientBatchSubscribe) Context() context.Context {
|
||||
return s.stream.Context()
|
||||
}
|
||||
|
||||
func (s *brokerServiceClientBatchSubscribe) SendMsg(msg interface{}) error {
|
||||
return s.stream.Send(msg)
|
||||
}
|
||||
|
||||
func (s *brokerServiceClientBatchSubscribe) RecvMsg(msg interface{}) error {
|
||||
return s.stream.Recv(msg)
|
||||
}
|
||||
|
||||
func (s *brokerServiceClientBatchSubscribe) Recv() (*proto.Message, error) {
|
||||
msg := &proto.Message{}
|
||||
if err := s.stream.Recv(msg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
type brokerServiceServer struct {
|
||||
BrokerServiceServer
|
||||
}
|
||||
|
||||
func (h *brokerServiceServer) Publish(ctx context.Context, req *proto.PublishRequest, rsp *proto.PublishResponse) error {
|
||||
return h.BrokerServiceServer.Publish(ctx, req, rsp)
|
||||
}
|
||||
|
||||
func (h *brokerServiceServer) BatchPublish(ctx context.Context, req *proto.BatchPublishRequest, rsp *proto.BatchPublishResponse) error {
|
||||
return h.BrokerServiceServer.BatchPublish(ctx, req, rsp)
|
||||
}
|
||||
|
||||
func (h *brokerServiceServer) Subscribe(ctx context.Context, stream server.Stream) error {
|
||||
msg := &proto.SubscribeRequest{}
|
||||
if err := stream.Recv(msg); err != nil {
|
||||
return err
|
||||
}
|
||||
return h.BrokerServiceServer.Subscribe(ctx, msg, &brokerServiceSubscribeStream{stream})
|
||||
}
|
||||
|
||||
type brokerServiceSubscribeStream struct {
|
||||
stream server.Stream
|
||||
}
|
||||
|
||||
func (s *brokerServiceSubscribeStream) Close() error {
|
||||
return s.stream.Close()
|
||||
}
|
||||
|
||||
func (s *brokerServiceSubscribeStream) Context() context.Context {
|
||||
return s.stream.Context()
|
||||
}
|
||||
|
||||
func (s *brokerServiceSubscribeStream) SendMsg(msg interface{}) error {
|
||||
return s.stream.Send(msg)
|
||||
}
|
||||
|
||||
func (s *brokerServiceSubscribeStream) RecvMsg(msg interface{}) error {
|
||||
return s.stream.Recv(msg)
|
||||
}
|
||||
|
||||
func (s *brokerServiceSubscribeStream) Send(msg *proto.Message) error {
|
||||
return s.stream.Send(msg)
|
||||
}
|
||||
|
||||
func (h *brokerServiceServer) BatchSubscribe(ctx context.Context, stream server.Stream) error {
|
||||
msg := &proto.BatchSubscribeRequest{}
|
||||
if err := stream.Recv(msg); err != nil {
|
||||
return err
|
||||
}
|
||||
return h.BrokerServiceServer.BatchSubscribe(ctx, msg, &brokerServiceBatchSubscribeStream{stream})
|
||||
}
|
||||
|
||||
type brokerServiceBatchSubscribeStream struct {
|
||||
stream server.Stream
|
||||
}
|
||||
|
||||
func (s *brokerServiceBatchSubscribeStream) Close() error {
|
||||
return s.stream.Close()
|
||||
}
|
||||
|
||||
func (s *brokerServiceBatchSubscribeStream) Context() context.Context {
|
||||
return s.stream.Context()
|
||||
}
|
||||
|
||||
func (s *brokerServiceBatchSubscribeStream) SendMsg(msg interface{}) error {
|
||||
return s.stream.Send(msg)
|
||||
}
|
||||
|
||||
func (s *brokerServiceBatchSubscribeStream) RecvMsg(msg interface{}) error {
|
||||
return s.stream.Recv(msg)
|
||||
}
|
||||
|
||||
func (s *brokerServiceBatchSubscribeStream) Send(msg *proto.Message) error {
|
||||
return s.stream.Send(msg)
|
||||
}
|
||||
|
||||
func RegisterBrokerServiceServer(s server.Server, sh BrokerServiceServer, opts ...server.HandlerOption) error {
|
||||
type brokerService interface {
|
||||
Publish(ctx context.Context, req *proto.PublishRequest, rsp *proto.PublishResponse) error
|
||||
BatchPublish(ctx context.Context, req *proto.BatchPublishRequest, rsp *proto.BatchPublishResponse) error
|
||||
Subscribe(ctx context.Context, stream server.Stream) error
|
||||
BatchSubscribe(ctx context.Context, stream server.Stream) error
|
||||
}
|
||||
type BrokerService struct {
|
||||
brokerService
|
||||
}
|
||||
h := &brokerServiceServer{sh}
|
||||
var nopts []server.HandlerOption
|
||||
for _, endpoint := range BrokerServiceEndpoints {
|
||||
nopts = append(nopts, api.WithEndpoint(&endpoint))
|
||||
}
|
||||
return s.Handle(s.NewHandler(&BrokerService{h}, append(nopts, opts...)...))
|
||||
}
|
20
options.go
Normal file
20
options.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
)
|
||||
|
||||
type clientKey struct{}
|
||||
|
||||
// Client to call broker service
|
||||
func Client(c client.Client) broker.Option {
|
||||
return broker.SetOption(clientKey{}, c)
|
||||
}
|
||||
|
||||
type serviceKey struct{}
|
||||
|
||||
// Service to call broker service
|
||||
func Service(name string) broker.Option {
|
||||
return broker.SetOption(serviceKey{}, name)
|
||||
}
|
587
proto/broker.pb.go
Normal file
587
proto/broker.pb.go
Normal file
@@ -0,0 +1,587 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.17.3
|
||||
// source: broker.proto
|
||||
|
||||
package servicepb
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type PublishRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Topic string `protobuf:"bytes,1,opt,name=topic,proto3" json:"topic,omitempty"`
|
||||
Message *Message `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (x *PublishRequest) Reset() {
|
||||
*x = PublishRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_broker_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *PublishRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*PublishRequest) ProtoMessage() {}
|
||||
|
||||
func (x *PublishRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_broker_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use PublishRequest.ProtoReflect.Descriptor instead.
|
||||
func (*PublishRequest) Descriptor() ([]byte, []int) {
|
||||
return file_broker_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *PublishRequest) GetTopic() string {
|
||||
if x != nil {
|
||||
return x.Topic
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *PublishRequest) GetMessage() *Message {
|
||||
if x != nil {
|
||||
return x.Message
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type BatchPublishRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Topic string `protobuf:"bytes,1,opt,name=topic,proto3" json:"topic,omitempty"`
|
||||
Message []*Message `protobuf:"bytes,2,rep,name=message,proto3" json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (x *BatchPublishRequest) Reset() {
|
||||
*x = BatchPublishRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_broker_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *BatchPublishRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*BatchPublishRequest) ProtoMessage() {}
|
||||
|
||||
func (x *BatchPublishRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_broker_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use BatchPublishRequest.ProtoReflect.Descriptor instead.
|
||||
func (*BatchPublishRequest) Descriptor() ([]byte, []int) {
|
||||
return file_broker_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *BatchPublishRequest) GetTopic() string {
|
||||
if x != nil {
|
||||
return x.Topic
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *BatchPublishRequest) GetMessage() []*Message {
|
||||
if x != nil {
|
||||
return x.Message
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type PublishResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
}
|
||||
|
||||
func (x *PublishResponse) Reset() {
|
||||
*x = PublishResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_broker_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *PublishResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*PublishResponse) ProtoMessage() {}
|
||||
|
||||
func (x *PublishResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_broker_proto_msgTypes[2]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use PublishResponse.ProtoReflect.Descriptor instead.
|
||||
func (*PublishResponse) Descriptor() ([]byte, []int) {
|
||||
return file_broker_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
type BatchPublishResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
}
|
||||
|
||||
func (x *BatchPublishResponse) Reset() {
|
||||
*x = BatchPublishResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_broker_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *BatchPublishResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*BatchPublishResponse) ProtoMessage() {}
|
||||
|
||||
func (x *BatchPublishResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_broker_proto_msgTypes[3]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use BatchPublishResponse.ProtoReflect.Descriptor instead.
|
||||
func (*BatchPublishResponse) Descriptor() ([]byte, []int) {
|
||||
return file_broker_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
type SubscribeRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Topic string `protobuf:"bytes,1,opt,name=topic,proto3" json:"topic,omitempty"`
|
||||
Group string `protobuf:"bytes,2,opt,name=group,proto3" json:"group,omitempty"`
|
||||
}
|
||||
|
||||
func (x *SubscribeRequest) Reset() {
|
||||
*x = SubscribeRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_broker_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *SubscribeRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*SubscribeRequest) ProtoMessage() {}
|
||||
|
||||
func (x *SubscribeRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_broker_proto_msgTypes[4]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use SubscribeRequest.ProtoReflect.Descriptor instead.
|
||||
func (*SubscribeRequest) Descriptor() ([]byte, []int) {
|
||||
return file_broker_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *SubscribeRequest) GetTopic() string {
|
||||
if x != nil {
|
||||
return x.Topic
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *SubscribeRequest) GetGroup() string {
|
||||
if x != nil {
|
||||
return x.Group
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type BatchSubscribeRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Topic string `protobuf:"bytes,1,opt,name=topic,proto3" json:"topic,omitempty"`
|
||||
Group string `protobuf:"bytes,2,opt,name=group,proto3" json:"group,omitempty"`
|
||||
}
|
||||
|
||||
func (x *BatchSubscribeRequest) Reset() {
|
||||
*x = BatchSubscribeRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_broker_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *BatchSubscribeRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*BatchSubscribeRequest) ProtoMessage() {}
|
||||
|
||||
func (x *BatchSubscribeRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_broker_proto_msgTypes[5]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use BatchSubscribeRequest.ProtoReflect.Descriptor instead.
|
||||
func (*BatchSubscribeRequest) Descriptor() ([]byte, []int) {
|
||||
return file_broker_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *BatchSubscribeRequest) GetTopic() string {
|
||||
if x != nil {
|
||||
return x.Topic
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *BatchSubscribeRequest) GetGroup() string {
|
||||
if x != nil {
|
||||
return x.Group
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Header map[string]string `protobuf:"bytes,1,rep,name=header,proto3" json:"header,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
Body []byte `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Message) Reset() {
|
||||
*x = Message{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_broker_proto_msgTypes[6]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Message) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Message) ProtoMessage() {}
|
||||
|
||||
func (x *Message) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_broker_proto_msgTypes[6]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Message.ProtoReflect.Descriptor instead.
|
||||
func (*Message) Descriptor() ([]byte, []int) {
|
||||
return file_broker_proto_rawDescGZIP(), []int{6}
|
||||
}
|
||||
|
||||
func (x *Message) GetHeader() map[string]string {
|
||||
if x != nil {
|
||||
return x.Header
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Message) GetBody() []byte {
|
||||
if x != nil {
|
||||
return x.Body
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_broker_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_broker_proto_rawDesc = []byte{
|
||||
0x0a, 0x0c, 0x62, 0x72, 0x6f, 0x6b, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09,
|
||||
0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x22, 0x54, 0x0a, 0x0e, 0x50, 0x75, 0x62,
|
||||
0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74,
|
||||
0x6f, 0x70, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69,
|
||||
0x63, 0x12, 0x2c, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x0b, 0x32, 0x12, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d,
|
||||
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22,
|
||||
0x59, 0x0a, 0x13, 0x42, 0x61, 0x74, 0x63, 0x68, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x12, 0x2c, 0x0a, 0x07,
|
||||
0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e,
|
||||
0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
|
||||
0x65, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x11, 0x0a, 0x0f, 0x50, 0x75,
|
||||
0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x16, 0x0a,
|
||||
0x14, 0x42, 0x61, 0x74, 0x63, 0x68, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73,
|
||||
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x3e, 0x0a, 0x10, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69,
|
||||
0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x70,
|
||||
0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x12,
|
||||
0x14, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
|
||||
0x67, 0x72, 0x6f, 0x75, 0x70, 0x22, 0x43, 0x0a, 0x15, 0x42, 0x61, 0x74, 0x63, 0x68, 0x53, 0x75,
|
||||
0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14,
|
||||
0x0a, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74,
|
||||
0x6f, 0x70, 0x69, 0x63, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x22, 0x90, 0x01, 0x0a, 0x07, 0x4d,
|
||||
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x36, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72,
|
||||
0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||
0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65,
|
||||
0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12,
|
||||
0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f,
|
||||
0x64, 0x79, 0x1a, 0x39, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x45, 0x6e, 0x74, 0x72,
|
||||
0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
|
||||
0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0xb4, 0x02,
|
||||
0x0a, 0x0d, 0x42, 0x72, 0x6f, 0x6b, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12,
|
||||
0x42, 0x0a, 0x07, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x12, 0x19, 0x2e, 0x73, 0x65, 0x72,
|
||||
0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70,
|
||||
0x62, 0x2e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||
0x65, 0x22, 0x00, 0x12, 0x51, 0x0a, 0x0c, 0x42, 0x61, 0x74, 0x63, 0x68, 0x50, 0x75, 0x62, 0x6c,
|
||||
0x69, 0x73, 0x68, 0x12, 0x1e, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e,
|
||||
0x42, 0x61, 0x74, 0x63, 0x68, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75,
|
||||
0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e,
|
||||
0x42, 0x61, 0x74, 0x63, 0x68, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70,
|
||||
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x09, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72,
|
||||
0x69, 0x62, 0x65, 0x12, 0x1b, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e,
|
||||
0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
0x1a, 0x12, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73,
|
||||
0x73, 0x61, 0x67, 0x65, 0x22, 0x00, 0x30, 0x01, 0x12, 0x4a, 0x0a, 0x0e, 0x42, 0x61, 0x74, 0x63,
|
||||
0x68, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x12, 0x20, 0x2e, 0x73, 0x65, 0x72,
|
||||
0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x42, 0x61, 0x74, 0x63, 0x68, 0x53, 0x75, 0x62, 0x73,
|
||||
0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x73,
|
||||
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
|
||||
0x22, 0x00, 0x30, 0x01, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x6f, 0x2e, 0x75, 0x6e, 0x69, 0x73, 0x74,
|
||||
0x61, 0x63, 0x6b, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d, 0x62, 0x72,
|
||||
0x6f, 0x6b, 0x65, 0x72, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x76, 0x33, 0x2f,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x62,
|
||||
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_broker_proto_rawDescOnce sync.Once
|
||||
file_broker_proto_rawDescData = file_broker_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_broker_proto_rawDescGZIP() []byte {
|
||||
file_broker_proto_rawDescOnce.Do(func() {
|
||||
file_broker_proto_rawDescData = protoimpl.X.CompressGZIP(file_broker_proto_rawDescData)
|
||||
})
|
||||
return file_broker_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_broker_proto_msgTypes = make([]protoimpl.MessageInfo, 8)
|
||||
var file_broker_proto_goTypes = []interface{}{
|
||||
(*PublishRequest)(nil), // 0: servicepb.PublishRequest
|
||||
(*BatchPublishRequest)(nil), // 1: servicepb.BatchPublishRequest
|
||||
(*PublishResponse)(nil), // 2: servicepb.PublishResponse
|
||||
(*BatchPublishResponse)(nil), // 3: servicepb.BatchPublishResponse
|
||||
(*SubscribeRequest)(nil), // 4: servicepb.SubscribeRequest
|
||||
(*BatchSubscribeRequest)(nil), // 5: servicepb.BatchSubscribeRequest
|
||||
(*Message)(nil), // 6: servicepb.Message
|
||||
nil, // 7: servicepb.Message.HeaderEntry
|
||||
}
|
||||
var file_broker_proto_depIdxs = []int32{
|
||||
6, // 0: servicepb.PublishRequest.message:type_name -> servicepb.Message
|
||||
6, // 1: servicepb.BatchPublishRequest.message:type_name -> servicepb.Message
|
||||
7, // 2: servicepb.Message.header:type_name -> servicepb.Message.HeaderEntry
|
||||
0, // 3: servicepb.BrokerService.Publish:input_type -> servicepb.PublishRequest
|
||||
1, // 4: servicepb.BrokerService.BatchPublish:input_type -> servicepb.BatchPublishRequest
|
||||
4, // 5: servicepb.BrokerService.Subscribe:input_type -> servicepb.SubscribeRequest
|
||||
5, // 6: servicepb.BrokerService.BatchSubscribe:input_type -> servicepb.BatchSubscribeRequest
|
||||
2, // 7: servicepb.BrokerService.Publish:output_type -> servicepb.PublishResponse
|
||||
3, // 8: servicepb.BrokerService.BatchPublish:output_type -> servicepb.BatchPublishResponse
|
||||
6, // 9: servicepb.BrokerService.Subscribe:output_type -> servicepb.Message
|
||||
6, // 10: servicepb.BrokerService.BatchSubscribe:output_type -> servicepb.Message
|
||||
7, // [7:11] is the sub-list for method output_type
|
||||
3, // [3:7] is the sub-list for method input_type
|
||||
3, // [3:3] is the sub-list for extension type_name
|
||||
3, // [3:3] is the sub-list for extension extendee
|
||||
0, // [0:3] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_broker_proto_init() }
|
||||
func file_broker_proto_init() {
|
||||
if File_broker_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_broker_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*PublishRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_broker_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*BatchPublishRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_broker_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*PublishResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_broker_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*BatchPublishResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_broker_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SubscribeRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_broker_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*BatchSubscribeRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_broker_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Message); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_broker_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 8,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_broker_proto_goTypes,
|
||||
DependencyIndexes: file_broker_proto_depIdxs,
|
||||
MessageInfos: file_broker_proto_msgTypes,
|
||||
}.Build()
|
||||
File_broker_proto = out.File
|
||||
file_broker_proto_rawDesc = nil
|
||||
file_broker_proto_goTypes = nil
|
||||
file_broker_proto_depIdxs = nil
|
||||
}
|
44
proto/broker.proto
Normal file
44
proto/broker.proto
Normal file
@@ -0,0 +1,44 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package servicepb;
|
||||
option go_package="go.unistack.org/micro-broker-service/v3/proto;servicepb";
|
||||
|
||||
service BrokerService {
|
||||
rpc Publish(PublishRequest) returns (PublishResponse) {};
|
||||
rpc BatchPublish(BatchPublishRequest) returns (BatchPublishResponse) {};
|
||||
rpc Subscribe(SubscribeRequest) returns (stream Message) {};
|
||||
rpc BatchSubscribe(BatchSubscribeRequest) returns (stream Message) {};
|
||||
};
|
||||
|
||||
message PublishRequest {
|
||||
string topic = 1;
|
||||
Message message = 2;
|
||||
};
|
||||
|
||||
message BatchPublishRequest {
|
||||
string topic = 1;
|
||||
repeated Message message = 2;
|
||||
};
|
||||
|
||||
message PublishResponse {
|
||||
|
||||
};
|
||||
|
||||
message BatchPublishResponse {
|
||||
|
||||
};
|
||||
|
||||
message SubscribeRequest {
|
||||
string topic = 1;
|
||||
string group = 2;
|
||||
};
|
||||
|
||||
message BatchSubscribeRequest {
|
||||
string topic = 1;
|
||||
string group = 2;
|
||||
};
|
||||
|
||||
message Message {
|
||||
map<string,string> header = 1;
|
||||
bytes body = 2;
|
||||
};
|
264
proto/broker_grpc.pb.go
Normal file
264
proto/broker_grpc.pb.go
Normal file
@@ -0,0 +1,264 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
|
||||
package servicepb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// BrokerServiceClient is the client API for BrokerService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type BrokerServiceClient interface {
|
||||
Publish(ctx context.Context, in *PublishRequest, opts ...grpc.CallOption) (*PublishResponse, error)
|
||||
BatchPublish(ctx context.Context, in *BatchPublishRequest, opts ...grpc.CallOption) (*BatchPublishResponse, error)
|
||||
Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (BrokerService_SubscribeClient, error)
|
||||
BatchSubscribe(ctx context.Context, in *BatchSubscribeRequest, opts ...grpc.CallOption) (BrokerService_BatchSubscribeClient, error)
|
||||
}
|
||||
|
||||
type brokerServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewBrokerServiceClient(cc grpc.ClientConnInterface) BrokerServiceClient {
|
||||
return &brokerServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *brokerServiceClient) Publish(ctx context.Context, in *PublishRequest, opts ...grpc.CallOption) (*PublishResponse, error) {
|
||||
out := new(PublishResponse)
|
||||
err := c.cc.Invoke(ctx, "/servicepb.BrokerService/Publish", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *brokerServiceClient) BatchPublish(ctx context.Context, in *BatchPublishRequest, opts ...grpc.CallOption) (*BatchPublishResponse, error) {
|
||||
out := new(BatchPublishResponse)
|
||||
err := c.cc.Invoke(ctx, "/servicepb.BrokerService/BatchPublish", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *brokerServiceClient) Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (BrokerService_SubscribeClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &BrokerService_ServiceDesc.Streams[0], "/servicepb.BrokerService/Subscribe", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &brokerServiceSubscribeClient{stream}
|
||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := x.ClientStream.CloseSend(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type BrokerService_SubscribeClient interface {
|
||||
Recv() (*Message, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
type brokerServiceSubscribeClient struct {
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *brokerServiceSubscribeClient) Recv() (*Message, error) {
|
||||
m := new(Message)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (c *brokerServiceClient) BatchSubscribe(ctx context.Context, in *BatchSubscribeRequest, opts ...grpc.CallOption) (BrokerService_BatchSubscribeClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &BrokerService_ServiceDesc.Streams[1], "/servicepb.BrokerService/BatchSubscribe", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &brokerServiceBatchSubscribeClient{stream}
|
||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := x.ClientStream.CloseSend(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type BrokerService_BatchSubscribeClient interface {
|
||||
Recv() (*Message, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
type brokerServiceBatchSubscribeClient struct {
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *brokerServiceBatchSubscribeClient) Recv() (*Message, error) {
|
||||
m := new(Message)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// BrokerServiceServer is the server API for BrokerService service.
|
||||
// All implementations must embed UnimplementedBrokerServiceServer
|
||||
// for forward compatibility
|
||||
type BrokerServiceServer interface {
|
||||
Publish(context.Context, *PublishRequest) (*PublishResponse, error)
|
||||
BatchPublish(context.Context, *BatchPublishRequest) (*BatchPublishResponse, error)
|
||||
Subscribe(*SubscribeRequest, BrokerService_SubscribeServer) error
|
||||
BatchSubscribe(*BatchSubscribeRequest, BrokerService_BatchSubscribeServer) error
|
||||
mustEmbedUnimplementedBrokerServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedBrokerServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedBrokerServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedBrokerServiceServer) Publish(context.Context, *PublishRequest) (*PublishResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Publish not implemented")
|
||||
}
|
||||
func (UnimplementedBrokerServiceServer) BatchPublish(context.Context, *BatchPublishRequest) (*BatchPublishResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method BatchPublish not implemented")
|
||||
}
|
||||
func (UnimplementedBrokerServiceServer) Subscribe(*SubscribeRequest, BrokerService_SubscribeServer) error {
|
||||
return status.Errorf(codes.Unimplemented, "method Subscribe not implemented")
|
||||
}
|
||||
func (UnimplementedBrokerServiceServer) BatchSubscribe(*BatchSubscribeRequest, BrokerService_BatchSubscribeServer) error {
|
||||
return status.Errorf(codes.Unimplemented, "method BatchSubscribe not implemented")
|
||||
}
|
||||
func (UnimplementedBrokerServiceServer) mustEmbedUnimplementedBrokerServiceServer() {}
|
||||
|
||||
// UnsafeBrokerServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to BrokerServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeBrokerServiceServer interface {
|
||||
mustEmbedUnimplementedBrokerServiceServer()
|
||||
}
|
||||
|
||||
func RegisterBrokerServiceServer(s grpc.ServiceRegistrar, srv BrokerServiceServer) {
|
||||
s.RegisterService(&BrokerService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _BrokerService_Publish_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(PublishRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(BrokerServiceServer).Publish(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/servicepb.BrokerService/Publish",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(BrokerServiceServer).Publish(ctx, req.(*PublishRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _BrokerService_BatchPublish_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(BatchPublishRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(BrokerServiceServer).BatchPublish(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/servicepb.BrokerService/BatchPublish",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(BrokerServiceServer).BatchPublish(ctx, req.(*BatchPublishRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _BrokerService_Subscribe_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
m := new(SubscribeRequest)
|
||||
if err := stream.RecvMsg(m); err != nil {
|
||||
return err
|
||||
}
|
||||
return srv.(BrokerServiceServer).Subscribe(m, &brokerServiceSubscribeServer{stream})
|
||||
}
|
||||
|
||||
type BrokerService_SubscribeServer interface {
|
||||
Send(*Message) error
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
type brokerServiceSubscribeServer struct {
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *brokerServiceSubscribeServer) Send(m *Message) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func _BrokerService_BatchSubscribe_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
m := new(BatchSubscribeRequest)
|
||||
if err := stream.RecvMsg(m); err != nil {
|
||||
return err
|
||||
}
|
||||
return srv.(BrokerServiceServer).BatchSubscribe(m, &brokerServiceBatchSubscribeServer{stream})
|
||||
}
|
||||
|
||||
type BrokerService_BatchSubscribeServer interface {
|
||||
Send(*Message) error
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
type brokerServiceBatchSubscribeServer struct {
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *brokerServiceBatchSubscribeServer) Send(m *Message) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
// BrokerService_ServiceDesc is the grpc.ServiceDesc for BrokerService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var BrokerService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "servicepb.BrokerService",
|
||||
HandlerType: (*BrokerServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "Publish",
|
||||
Handler: _BrokerService_Publish_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "BatchPublish",
|
||||
Handler: _BrokerService_BatchPublish_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{
|
||||
{
|
||||
StreamName: "Subscribe",
|
||||
Handler: _BrokerService_Subscribe_Handler,
|
||||
ServerStreams: true,
|
||||
},
|
||||
{
|
||||
StreamName: "BatchSubscribe",
|
||||
Handler: _BrokerService_BatchSubscribe_Handler,
|
||||
ServerStreams: true,
|
||||
},
|
||||
},
|
||||
Metadata: "broker.proto",
|
||||
}
|
199
service.go
199
service.go
@@ -1,16 +1,201 @@
|
||||
// Package service provides the broker service client
|
||||
package service
|
||||
package service // import "go.unistack.org/micro-broker-service/v3"
|
||||
|
||||
import (
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
"github.com/micro/go-micro/v2/broker/service"
|
||||
"github.com/micro/go-micro/v2/cmd"
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
pbmicro "go.unistack.org/micro-broker-service/v3/micro"
|
||||
pb "go.unistack.org/micro-broker-service/v3/proto"
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd.DefaultBrokers["service"] = NewBroker
|
||||
type serviceBroker struct {
|
||||
addrs []string
|
||||
service string
|
||||
client pbmicro.BrokerServiceClient
|
||||
init bool
|
||||
opts broker.Options
|
||||
}
|
||||
|
||||
func (b *serviceBroker) Address() string {
|
||||
return b.addrs[0]
|
||||
}
|
||||
|
||||
func (b *serviceBroker) Connect(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *serviceBroker) Disconnect(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *serviceBroker) Init(opts ...broker.Option) error {
|
||||
if len(opts) == 0 && b.init {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&b.opts)
|
||||
}
|
||||
|
||||
var cli client.Client
|
||||
if b.opts.Context != nil {
|
||||
if v, ok := b.opts.Context.Value(clientKey{}).(client.Client); ok && v != nil {
|
||||
cli = v
|
||||
}
|
||||
if v, ok := b.opts.Context.Value(serviceKey{}).(string); ok && v != "" {
|
||||
b.service = v
|
||||
}
|
||||
}
|
||||
|
||||
if err := b.opts.Register.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := b.opts.Tracer.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := b.opts.Logger.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := b.opts.Meter.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if b.service == "" {
|
||||
return fmt.Errorf("missing Service option")
|
||||
}
|
||||
|
||||
if cli == nil {
|
||||
return fmt.Errorf("missing Client option")
|
||||
}
|
||||
|
||||
b.client = pbmicro.NewBrokerServiceClient(b.service, cli)
|
||||
|
||||
b.init = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *serviceBroker) Options() broker.Options {
|
||||
return b.opts
|
||||
}
|
||||
|
||||
func (b *serviceBroker) BatchPublish(ctx context.Context, msgs []*broker.Message, opts ...broker.PublishOption) error {
|
||||
return b.publish(ctx, msgs, opts...)
|
||||
}
|
||||
|
||||
func (b *serviceBroker) Publish(ctx context.Context, topic string, msg *broker.Message, opts ...broker.PublishOption) error {
|
||||
msg.Header.Set(metadata.HeaderTopic, topic)
|
||||
return b.publish(ctx, []*broker.Message{msg}, opts...)
|
||||
}
|
||||
|
||||
func (b *serviceBroker) publish(ctx context.Context, msgs []*broker.Message, opts ...broker.PublishOption) error {
|
||||
for _, msg := range msgs {
|
||||
topic, _ := msg.Header.Get(metadata.HeaderTopic)
|
||||
if logger.V(logger.TraceLevel) {
|
||||
logger.Tracef(ctx, "Publishing to topic %s broker %v", topic, b.addrs)
|
||||
}
|
||||
_, err := b.client.Publish(ctx, &pb.PublishRequest{
|
||||
Topic: topic,
|
||||
Message: &pb.Message{
|
||||
Header: msg.Header,
|
||||
Body: msg.Body,
|
||||
},
|
||||
}, client.WithAddress(b.addrs...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *serviceBroker) BatchSubscribe(ctx context.Context, topic string, handler broker.BatchHandler, opts ...broker.SubscribeOption) (broker.Subscriber, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (b *serviceBroker) Subscribe(ctx context.Context, topic string, handler broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) {
|
||||
options := broker.NewSubscribeOptions(opts...)
|
||||
if logger.V(logger.TraceLevel) {
|
||||
logger.Tracef(ctx, "Subscribing to topic %s group %s broker %v", topic, options.Group, b.addrs)
|
||||
}
|
||||
stream, err := b.client.Subscribe(ctx, &pb.SubscribeRequest{
|
||||
Topic: topic,
|
||||
Group: options.Group,
|
||||
}, client.WithAddress(b.addrs...), client.WithRequestTimeout(time.Hour))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sub := &serviceSub{
|
||||
topic: topic,
|
||||
group: options.Group,
|
||||
handler: handler,
|
||||
stream: stream,
|
||||
closed: make(chan bool),
|
||||
options: options,
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-sub.closed:
|
||||
if logger.V(logger.TraceLevel) {
|
||||
logger.Tracef(ctx, "Unsubscribed from topic %s", topic)
|
||||
}
|
||||
return
|
||||
default:
|
||||
if logger.V(logger.TraceLevel) {
|
||||
// run the subscriber
|
||||
logger.Tracef(ctx, "Streaming from broker %v to topic [%s] group [%s]", b.addrs, topic, options.Group)
|
||||
}
|
||||
if err := sub.run(ctx); err != nil {
|
||||
if logger.V(logger.TraceLevel) {
|
||||
logger.Tracef(ctx, "Resubscribing to topic %s broker %v", topic, b.addrs)
|
||||
}
|
||||
stream, err := b.client.Subscribe(ctx, &pb.SubscribeRequest{
|
||||
Topic: topic,
|
||||
Group: options.Group,
|
||||
}, client.WithAddress(b.addrs...), client.WithRequestTimeout(time.Hour))
|
||||
if err != nil {
|
||||
if logger.V(logger.TraceLevel) {
|
||||
logger.Tracef(ctx, "Failed to resubscribe to topic %s: %v", topic, err)
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
}
|
||||
// new stream
|
||||
sub.stream = stream
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return sub, nil
|
||||
}
|
||||
|
||||
func (b *serviceBroker) String() string {
|
||||
return "service"
|
||||
}
|
||||
|
||||
func (b *serviceBroker) Name() string {
|
||||
return b.opts.Name
|
||||
}
|
||||
|
||||
func NewBroker(opts ...broker.Option) broker.Broker {
|
||||
return service.NewBroker(opts...)
|
||||
options := broker.NewOptions(opts...)
|
||||
|
||||
addrs := options.Addrs
|
||||
if len(addrs) == 0 {
|
||||
addrs = []string{"127.0.0.1:8001"}
|
||||
}
|
||||
|
||||
return &serviceBroker{
|
||||
addrs: addrs,
|
||||
opts: options,
|
||||
}
|
||||
}
|
||||
|
114
subscriber.go
Normal file
114
subscriber.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pbmicro "go.unistack.org/micro-broker-service/v3/micro"
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
)
|
||||
|
||||
type serviceSub struct {
|
||||
topic string
|
||||
group string
|
||||
handler broker.Handler
|
||||
stream pbmicro.BrokerService_SubscribeClient
|
||||
closed chan bool
|
||||
options broker.SubscribeOptions
|
||||
}
|
||||
|
||||
type serviceEvent struct {
|
||||
topic string
|
||||
err error
|
||||
message *broker.Message
|
||||
}
|
||||
|
||||
func (s *serviceEvent) Topic() string {
|
||||
return s.topic
|
||||
}
|
||||
|
||||
func (s *serviceEvent) Message() *broker.Message {
|
||||
return s.message
|
||||
}
|
||||
|
||||
func (s *serviceEvent) Ack() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *serviceEvent) Error() error {
|
||||
return s.err
|
||||
}
|
||||
|
||||
func (s *serviceEvent) SetError(err error) {
|
||||
s.err = err
|
||||
}
|
||||
|
||||
func (s *serviceSub) isClosed() bool {
|
||||
select {
|
||||
case <-s.closed:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (s *serviceSub) run(ctx context.Context) error {
|
||||
exit := make(chan bool)
|
||||
go func() {
|
||||
select {
|
||||
case <-exit:
|
||||
case <-s.closed:
|
||||
}
|
||||
|
||||
// close the stream
|
||||
s.stream.Close()
|
||||
}()
|
||||
|
||||
for {
|
||||
// TODO: do not fail silently
|
||||
msg, err := s.stream.Recv()
|
||||
if err != nil {
|
||||
if logger.V(logger.TraceLevel) {
|
||||
logger.Tracef(ctx, "Streaming error for subcription to topic %s: %v", s.Topic(), err)
|
||||
}
|
||||
|
||||
// close the exit channel
|
||||
close(exit)
|
||||
|
||||
// don't return an error if we unsubscribed
|
||||
if s.isClosed() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// return stream error
|
||||
return err
|
||||
}
|
||||
|
||||
p := &serviceEvent{
|
||||
topic: s.topic,
|
||||
message: &broker.Message{
|
||||
Header: msg.Header,
|
||||
Body: msg.Body,
|
||||
},
|
||||
}
|
||||
p.err = s.handler(p)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *serviceSub) Options() broker.SubscribeOptions {
|
||||
return s.options
|
||||
}
|
||||
|
||||
func (s *serviceSub) Topic() string {
|
||||
return s.topic
|
||||
}
|
||||
|
||||
func (s *serviceSub) Unsubscribe(ctx context.Context) error {
|
||||
select {
|
||||
case <-s.closed:
|
||||
return nil
|
||||
default:
|
||||
close(s.closed)
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user