diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index cf27a37024..0000000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -service_name: travis-pro diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000000..381e4d77e6 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1 @@ +#TBD \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..1d0cbfc626 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,84 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +name: "Continuous Integration" + +on: + push: + branches: + - develop + pull_request: + branches: + - develop + workflow_dispatch: + +jobs: + build: + name: Build + + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: + - 'java' + java: + - 8 + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + # 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 + languages: ${{ matrix.language }} + + - name: Set up JDK ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + + - name: Build + run: ./gradlew clean build jacocoTestReport + + - name: Perform CodeQL analysis + uses: github/codeql-action/analyze@v1 + + - name: Upload coverage report to codecov.io + run: bash <(curl -s https://codecov.io/bash) || echo 'Failed to upload coverage report!' + + license-check: + name: License Check + + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Check license header + uses: apache/skywalking-eyes@9bd5feb86b5817aa6072b008f9866a2c3bbc8587 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/gitee-mirror.yml b/.github/workflows/gitee-mirror.yml deleted file mode 100644 index b29e0806f6..0000000000 --- a/.github/workflows/gitee-mirror.yml +++ /dev/null @@ -1,60 +0,0 @@ -# 使用 GitHub Action 来解决手动同步到 Gitee 的问题 -# 效果:github repo 代码更新之后,会自动同步至 gitee -# 使用到的 GitHub Action:https://github.com/Yikun/hub-mirror-action - -# This is a basic workflow to help you get started with Actions - -name: Gitee Mirror - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch -on: - push: - branches: - - '*' - -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - - name: Mirror the Github organization repos to Gitee. - uses: Yikun/hub-mirror-action@master - with: - src: github/WeBankFinTech - dst: gitee/webank - # 这里请填写与gitee上公钥匹配的的 ssh private key,参见:https://gitee.com/profile/sshkeys - # 填写地址:https://github.com/WeBankFinTech/fes.js/settings/secrets - dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} - # 这里请填写 gitee的令牌,参见:https://gitee.com/profile/personal_access_tokens - # 填写地址:https://github.com/WeBankFinTech/fes.js/settings/secrets - dst_token: ${{ secrets.GITEE_TOKEN }} - # 项目同步白名单,可以选择填写多个,以英文逗号分割 - static_list: "EventMesh" - # 是否强制同步 - force_update: true - # 账号类型:对 luban-h5 而言是 user,因为是个人项目;如果是企业项目,请填写 org,因为是组织下的项目 - account_type: org - clone_style: ssh - - build-and-deploy: - runs-on: ubuntu-latest - steps: - - name: Checkout 🛎️ - uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly. - with: - persist-credentials: false - - - name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built. - run: | - yarn install - yarn run docs:build - - name: Deploy 🚀 - uses: JamesIves/github-pages-deploy-action@3.7.1 - with: - GITHUB_TOKEN: ${{ secrets.EVENTMESH }} - BRANCH: gh-pages - FOLDER: docs/.vuepress/dist # The folder the action should deploy. diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml new file mode 100644 index 0000000000..8883906d2e --- /dev/null +++ b/.github/workflows/greetings.yml @@ -0,0 +1,72 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +name: Greetings + +on: [pull_request, issues] + +jobs: + greeting: + name: Greeting + runs-on: ubuntu-latest + steps: + - uses: actions/first-interaction@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + issue-message: | + Welcome to the Apache EventMesh (incubating) community!! + We are glad that you are contributing by opening this issue. :D + + Please make sure to include all the relevant context. + We will be here shortly. + + If you are interested in contributing to our project, please let us know! + You can check out our contributing guide on [contributing to EventMesh](https://github.com/apache/incubator-eventmesh/blob/develop/CONTRIBUTING.md). + + Want to get closer to the community? + + WeChat Group: + ![wechat_qr](https://github.com/apache/incubator-eventmesh/blob/develop/docs/images/mesh-helper.png?raw=true) + + Mailing Lists: + | Name | Description |Subscribe |Unsubscribe|Archive + | ---- | ---- |---- | ---- | ---- | + |Users |User support and questions mailing list| [Subscribe](mailto:users-subscribe@eventmesh.incubator.apache.org) |[Unsubscribe](mailto:users-unsubscribe@eventmesh.incubator.apache.org) |[Mail Archives](https://lists.apache.org/list.html?users@eventmesh.apache.org)| + |Development |Development related discussions| [Subscribe](mailto:dev-subscribe@eventmesh.incubator.apache.org) |[Unsubscribe](mailto:dev-unsubscribe@eventmesh.incubator.apache.org) |[Mail Archives](https://lists.apache.org/list.html?dev@eventmesh.apache.org)| + |Commits |All commits to repositories| [Subscribe](mailto:commits-subscribe@eventmesh.incubator.apache.org) |[Unsubscribe](mailto:commits-unsubscribe@eventmesh.incubator.apache.org) |[Mail Archives](https://lists.apache.org/list.html?commits@eventmesh.apache.org)| + + pr-message: | + Welcome to the Apache EventMesh (incubating) community!! + This is your first PR in our project. We're very excited to have you onboard contributing. Your contributions are greatly appreciated! + + Please make sure that the changes are covered by tests. + We will be here shortly. + Let us know if you need any help! + + Want to get closer to the community? + + WeChat Group: + ![wechat_qr](https://github.com/apache/incubator-eventmesh/blob/develop/docs/images/mesh-helper.png?raw=true) + + Mailing Lists: + | Name | Description |Subscribe |Unsubscribe|Archive + | ---- | ---- |---- | ---- | ---- | + |Users |User support and questions mailing list| [Subscribe](mailto:users-subscribe@eventmesh.incubator.apache.org) |[Unsubscribe](mailto:users-unsubscribe@eventmesh.incubator.apache.org) |[Mail Archives](https://lists.apache.org/list.html?users@eventmesh.apache.org)| + |Development |Development related discussions| [Subscribe](mailto:dev-subscribe@eventmesh.incubator.apache.org) |[Unsubscribe](mailto:dev-unsubscribe@eventmesh.incubator.apache.org) |[Mail Archives](https://lists.apache.org/list.html?dev@eventmesh.apache.org)| + |Commits |All commits to repositories| [Subscribe](mailto:commits-subscribe@eventmesh.incubator.apache.org) |[Unsubscribe](mailto:commits-unsubscribe@eventmesh.incubator.apache.org) |[Mail Archives](https://lists.apache.org/list.html?commits@eventmesh.apache.org)| diff --git a/.licenserc.yaml b/.licenserc.yaml new file mode 100644 index 0000000000..5046f8e188 --- /dev/null +++ b/.licenserc.yaml @@ -0,0 +1,41 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +header: + license: + spdx-id: Apache-2.0 + copyright-owner: Apache Software Foundation + + paths-ignore: + - '.github/PULL_REQUEST_TEMPLATE' + - '.gitmodules' + - '**/.gitkeep' + - '**/.gitignore' + - '**/*.md' + - '**/*.json' + - '**/*.ftl' + - '**/*.iml' + - '**/*.ini' + - '**/*.crt' + - '**/*.pem' + - 'LICENSE' + - 'NOTICE' + - 'DISCLAIMER-WIP' + + comment: on-failure diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a6b1867585..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -dist: trusty - -language: java -jdk: - - oraclejdk8 - -script: - - travis_retry ./gradlew clean build - -#after_success: -# - ./gradlew clean - -env: - global: - - secure: "T1QAuaAzcB7K8YjAAVVb4P9+W0JAdOFbyBwRxliyyoSZUShlIqa0eE7ioXHXWBP/d5f3XtROse6lq2qILqcU9sFSncKE2vRJlwJ5p7R23WIsCXdV70A9AVE2gLJcIJiOTMwd/YYYzNDrGLp3CSJNcKo8t7t70V2j/11I9xPTOHnaZ8FHGC3d/7bjfR/+g/3d4EOCvV8Vm6ndEmmailmF8OJ/kcbuRbArKIehjUwNDyQZfwAc9+vvPZlHgnQvR1pJ/KiK6muEIi7RQohDq7lMTmcc2LZSYgy/+aqFrmBcQwXScABFmSwysQ4KMXfrCqqMsBdmvno/NoKVGofHHKdym/oauv/G3lxLx5sgM9A7ZSFBK08x08r7u/6TDsTFmQ9LzVFDNo/OLZhxs3dr9x2C9Pa2A7IP1i1oVbbYkwBJv4z6o3khWpQAAY/IWijlCZ9vkjFfqdIXbvlPqamEaFRAmK5I3MVqL2+eBF+2Or/zwv4rXjo+v5LUKTfmDl77QUshPv6J+hblbBR0cJ/ZTSh9rHgdqhEzPGSt3e0YrEefkKWfinBr8TjIsHgQgmfU8Kz7gf7tvioOuAgKj4WlgEQJs3dPp7J5zxFVNMM6teAMFy8c2MtAdzKrs13Ri1qZWtL6B7JWlH6yhHqhKghyJhRjUFNVZnBkA/z9gzDKZ+tz2m8=" \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bfa29b93e5..68c870c4b2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,7 +32,7 @@ Here are the workflow for contributors: 7. Create a pull request Please follow [the pull request template](./.github/PULL_REQUEST_TEMPLATE.md). Please make sure the PR has a -corresponding issue. [GitHub Issues](https://github.com/WeBankFinTech/EventMesh/issues) +corresponding issue. [GitHub Issues](https://github.com/apache/incubator-eventmesh/issues) After creating a PR, one or more reviewers will be assigned to the pull request. The reviewers will review the code. @@ -41,11 +41,11 @@ message should be clear and concise. ### Open an issue / PR -We use [GitHub Issues](https://github.com/WeBankFinTech/EventMesh/issues) -and [Pull Requests](https://github.com/WeBankFinTech/EventMesh/pulls) for trackers. +We use [GitHub Issues](https://github.com/apache/incubator-eventmesh/issues) +and [Pull Requests](https://github.com/apache/incubator-eventmesh/pulls) for trackers. If you find a typo in a document, find a bug in code, or want new features, or want to give suggestions, you -can [open an issue on GitHub](https://github.com/WeBankFinTech/EventMesh/issues/new) to report it. Please follow the +can [open an issue on GitHub](https://github.com/apache/incubator-eventmesh/issues/new) to report it. Please follow the guideline message in the issue template. If you want to contribute, please follow the [contribution workflow](#github-workflow) and create a new pull request. If diff --git a/CONTRIBUTING.zh-CN.md b/CONTRIBUTING.zh-CN.md index 03bec9c925..742ccbdc32 100644 --- a/CONTRIBUTING.zh-CN.md +++ b/CONTRIBUTING.zh-CN.md @@ -29,7 +29,7 @@ 7. 创建PR合并请求 请遵循[Pull Requests模板](./.github/PULL_REQUEST_TEMPLATE.md). -请确保PR对应有相应的问题. [GitHub Issues](https://github.com/WeBankFinTech/EventMesh/issues) +请确保PR对应有相应的问题. [GitHub Issues](https://github.com/apache/incubator-eventmesh/issues) 创建PR后,将为拉取请求分配一个或多个审阅者。 审阅者将审阅代码。 @@ -38,10 +38,10 @@ ### 打开问题/ PR 我们将使用Issues和Pull Requests作为跟踪器 -[GitHub Issues](https://github.com/WeBankFinTech/EventMesh/issues) -[Pull Requests](https://github.com/WeBankFinTech/EventMesh/pulls) +[GitHub Issues](https://github.com/apache/incubator-eventmesh/issues) +[Pull Requests](https://github.com/apache/incubator-eventmesh/pulls) -如果您在文档中发现拼写错误,在代码中发现错误,想要新功能或提出建议, 您可以提出问题[在GitHub上打开问题](https://github.com/WeBankFinTech/EventMesh/issues/new) +如果您在文档中发现拼写错误,在代码中发现错误,想要新功能或提出建议, 您可以提出问题[在GitHub上打开问题](https://github.com/apache/incubator-eventmesh/issues/new) 请按照问题模板中的准则消息进行操作。 如果您想贡献,请遵循[贡献工作流程](#github-workflow)并创建一个新的拉取请求。 如果您的PR包含较大的更改,例如组件重构或新组件,请写详细文档 有关其设计和使用的信息。 diff --git a/README.md b/README.md index d6429cc1d6..43cfc861ab 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ -[![Build Status](https://www.travis-ci.org/apache/incubator-eventmesh.svg?branch=develop)](https://www.travis-ci.org/github/apache/incubator-eventmesh) -[![Coverage Status](https://coveralls.io/repos/github/WeBankFinTech/DeFiBus/badge.svg?branch=master)](https://coveralls.io/github/WeBankFinTech/EventMesh?branch=master) -[![GitHub release](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/WeBankFinTech/EventMesh/releases) +# Apache EventMesh (incubating) +[![CI status](https://github.com/apache/incubator-eventmesh/actions/workflows/ci.yml/badge.svg)](https://github.com/apache/incubator-eventmesh/actions/workflows/ci.yml) +[![CodeCov](https://codecov.io/gh/apache/incubator-eventmesh/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/incubator-eventmesh) +[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/apache/incubator-eventmesh.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/incubator-eventmesh/context:java) +[![Total alerts](https://img.shields.io/lgtm/alerts/g/apache/incubator-eventmesh.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/incubator-eventmesh/alerts/) +[![GitHub release](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/apache/incubator-eventmesh/releases) [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) [点我查看中文版](README.zh-CN.md) +![logo](docs/images/logo2.png) ## What is EventMesh? EventMesh(incubating) is a dynamic cloud-native eventing infrastruture used to decouple the application and backend middleware layer, which supports a wide range of use cases that encompass complex multi-cloud, widely distributed topologies using diverse technology stacks. @@ -22,17 +26,6 @@ EventMesh(incubating) is a dynamic cloud-native eventing infrastruture used to d ![architecture2](docs/images/eventmesh-panels.png) -The EventMesh(incubating) allows events from one application to be dynamically routed to any other application. -General functions of the eventmesh: - -* Event driven; -* Event governance; -* Event routing; -* Flow control; -* Load balance; -* Pluggable; -* Cloud native; -* Gateway **Support connecting event store:** @@ -41,12 +34,13 @@ General functions of the eventmesh: **Components:** * **eventmesh-runtime** : an middleware to transmit events between event producers and consumers, support cloud native apps and microservices. -* **eventmesh-sdk-java** : currently supports HTTP and TCP protocols, and will support gRPC in the future. -* **eventmesh-connector-rocketmq** : an implementation based on OpenMessaging Connector Interface, pub event to or sub event from RocketMQ Event Store. +* **eventmesh-sdk-java** : currently supports HTTP and TCP protocols. +* **eventmesh-connector-api** : an api layer based on OpenMessaging api and SPI pluggin, which can be implemented by popular EventStores such as IMDG, Messaging Engine and OSS etc. +* **eventmesh-connector-rocketmq** : an implementation of eventmesh-connector-api, pub event to or sub event from RocketMQ as EventStore. **Protocol:** -The protocol of eventmesh is easier and convenient, you can read more [here](docs/en/instructions/eventmesh-runtime-protocol.md) +The protocol of eventmesh is easier and more convenient, you can read more [here](docs/en/instructions/eventmesh-runtime-protocol.md) ## RoadMap | version | feature | @@ -54,7 +48,7 @@ The protocol of eventmesh is easier and convenient, you can read more [here](doc | v1.0.0 |Support java-sdk , tcp pub/sub, http pub| | v1.1.0 |Support RocketMQ as eventstore| | v1.1.1 |Support https| -| v1.2.0 |Support OpenMessaging API,support Plug-in architecture, support http sub, support cloud native deploy| +| v1.2.0 |Support EventMesh store layer pluggable by OpenMessaging Pub/Sub API, http sub, docker| | V1.3.0 |Support CloudEvents, Event Streaming| | |Support Event function,triggers and bindings| | |Support Event orchestration, Servelss workflow| diff --git a/README.zh-CN.md b/README.zh-CN.md index 76c450e78b..8dadfaa24a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,10 +1,15 @@ -[![Build Status](https://www.travis-ci.org/WeBankFinTech/DeFiBus.svg?branch=master)](https://www.travis-ci.org/WeBankFinTech/EventMesh) -[![Coverage Status](https://coveralls.io/repos/github/WeBankFinTech/DeFiBus/badge.svg?branch=master)](https://coveralls.io/github/WeBankFinTech/EventMesh?branch=master) -[![GitHub release](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/WeBankFinTech/EventMesh/releases) +# Apache EventMesh (incubating) +[![CI status](https://github.com/apache/incubator-eventmesh/actions/workflows/ci.yml/badge.svg)](https://github.com/apache/incubator-eventmesh/actions/workflows/ci.yml) +[![CodeCov](https://codecov.io/gh/apache/incubator-eventmesh/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/incubator-eventmesh) +[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/apache/incubator-eventmesh.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/incubator-eventmesh/context:java) +[![Total alerts](https://img.shields.io/lgtm/alerts/g/apache/incubator-eventmesh.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/incubator-eventmesh/alerts/) +[![GitHub release](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/apache/incubator-eventmesh/releases) [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) +![logo](docs/images/logo2.png) ## 什么是Event Mesh? EventMesh是一个动态的云原生事件驱动架构基础设施,用于分离应用程序和后端中间件层,它支持广泛的用例,包括复杂的混合云、使用了不同技术栈的分布式架构。 + ![architecture1](docs/images/eventmesh-multi-runtime.png) **EventMesh生态:** @@ -18,15 +23,6 @@ EventMesh是一个动态的云原生事件驱动架构基础设施,用于分 ![architecture2](docs/images/eventmesh-panels.png) -Event Mesh允许将来自一个应用程序的事件动态路由到任何其他应用程序. -Event Mesh的一般功能: -* 事件驱动; -* 事件治理; -* 动态路由; -* 云原生; -* 流控; -* 负载均衡 - **支持连接的事件存储:** * [RocketMQ](https://github.com/apache/rocketmq):RocketMQ是一个分布式消息流平台,具有低延迟、高性能和可靠性、万亿级容量和灵活的可伸缩性。 @@ -35,7 +31,8 @@ Event Mesh的一般功能: * **eventmesh-runtime**:一种中间件,用于在事件产生者和使用者之间传输事件,支持云原生应用程序和微服务 * **eventmesh-sdk-java**:当前支持HTTP和TCP协议,未来会支持gRPC等 -* **eventmesh-connector-rocketmq** : 一种基于OpenMessagingConnector 接口的实现,该实现支持将RocketMQ作为事件存储,实现事件的发布与订阅 +* **eventmesh-connector-api**:一个基于OpenMessaging api和SPI插件机制的接口层,可以有很多不同的事件存储的实现,比如IMDG,Messaging Engine和OSS等 +* **eventmesh-connector-rocketmq** : 一种基于eventmesh-connector-api的实现,该实现支持将RocketMQ作为事件存储,实现事件的发布与订阅 **通信协议:** @@ -47,7 +44,7 @@ eventmesh的通信协议更加简洁方便,详细内容,阅读更多[这里] | v1.0.0 |Support java-sdk , tcp pub/sub, http pub| | v1.1.0 |Support RocketMQ as eventstore| | v1.1.1 |Support https| -| v1.2.0 |Support OpenMessaging API,support Plug-in architecture, support http sub, support cloud native deploy| +| v1.2.0 |Support EventMesh store layer pluggable by OpenMessaging Pub/Sub API, http sub, docker| | V1.3.0 |Support CloudEvents, Event Streaming| | |Support Event function,triggers and bindings| | |Support Event orchestration, Servelss workflow| @@ -76,7 +73,15 @@ eventmesh的通信协议更加简洁方便,详细内容,阅读更多[这里] ## License [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) Copyright (C) Apache Software Foundation -## 联系人 +## 开发社区 微信群: ![wechat_qr](docs/images/mesh-helper.png) + +Mailing Lists: + +| 列表名称 | 描述 |订阅 |取消订阅|邮件列表存档 +| ---- | ---- |---- | ---- | ---- | +|Users |用户支持与用户问题| [点击订阅](mailto:users-subscribe@eventmesh.incubator.apache.org) |[点击取消订阅](mailto:users-unsubscribe@eventmesh.incubator.apache.org) |[邮件列表存档](https://lists.apache.org/list.html?users@eventmesh.apache.org)| +|Development |开发相关| [点击订阅](mailto:dev-subscribe@eventmesh.incubator.apache.org) |[点击取消订阅](mailto:dev-unsubscribe@eventmesh.incubator.apache.org) |[邮件列表存档](https://lists.apache.org/list.html?dev@eventmesh.apache.org)| +|Commits |所有与仓库相关的commits信息通知| [点击订阅](mailto:commits-subscribe@eventmesh.incubator.apache.org) |[点击取消订阅](mailto:commits-unsubscribe@eventmesh.incubator.apache.org) |[邮件列表存档](https://lists.apache.org/list.html?commits@eventmesh.apache.org)| diff --git a/build.gradle b/build.gradle index e285ba43e8..12a2b005e9 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,6 @@ buildscript { maven { url "https://plugins.gradle.org/m2/" } - } dependencies { @@ -41,7 +40,6 @@ allprojects { apply plugin: "eclipse" apply plugin: "idea" apply plugin: "project-reports" - apply plugin: "maven" apply plugin: "maven-publish" apply plugin: "com.github.spotbugs" apply plugin: "project-reports" @@ -50,6 +48,7 @@ allprojects { apply plugin: "java-library" apply plugin: 'signing' +// print(project) // if (project.findProperty("jdk") == "1.7") { // sourceCompatibility = 1.7 // targetCompatibility = 1.7 @@ -59,12 +58,10 @@ allprojects { // targetCompatibility = 1.8 // version = version + "-jdk8" // } - [compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8' compileJava.options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" - clean.doFirst { delete 'build' delete 'dist' @@ -74,7 +71,6 @@ allprojects { if ((project.findProperty("snapshot") instanceof String) && (Boolean.valueOf(project.property("snapshot")))) { version = version + "-SNAPSHOT" } - } task tar(type: Tar) { @@ -97,7 +93,6 @@ task zip(type: Zip) { } } - subprojects { List fastjson = [ @@ -135,6 +130,13 @@ subprojects { "org.slf4j:slf4j-api:1.7.30" ] + List log4j2 = [ + "org.apache.logging.log4j:log4j-api:2.13.3", + "org.apache.logging.log4j:log4j-core:2.13.3", + "org.apache.logging.log4j:log4j-slf4j-impl:2.13.3", + "org.apache.logging.log4j:log4j-web:2.13.3", + "com.lmax:disruptor:3.4.2" + ] List common = [ "commons-io:commons-io:2.4", @@ -152,13 +154,12 @@ subprojects { ] dependencies { - implementation apache_commons, guava, log, fastjson, jackson, common, httpclient, netty - testImplementation apache_commons, guava, log, fastjson, jackson, common, junit, assertj, mock, httpclient, netty + implementation apache_commons, guava, log, log4j2, fastjson, jackson, common, httpclient, netty + testImplementation apache_commons, guava, log, log4j2, fastjson, jackson, common, junit, assertj, mock, httpclient, netty spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.11.0' spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7' } - sourceSets { main { java.srcDirs = ['src/main/java'] @@ -176,17 +177,13 @@ subprojects { jacoco { toolVersion = "0.8.6" - reportsDir = file("$buildDir/reports/jacoco") } jacocoTestReport { -// sourceSets sourceSets.main -// executionData files("$buildDir/jacoco/jacocoTest.exec") - reports { - xml.enabled false + xml.enabled true csv.enabled false - html.destination file("${buildDir}/reports/jacoco/html") + html.enabled false } } @@ -204,7 +201,7 @@ subprojects { // html.enabled true // } // } - +// // sourceSets { // main { // java { @@ -227,11 +224,8 @@ subprojects { // } // // } -// -// // } - spotbugs { //toolVersion = '4.2.3' ignoreFailures = true @@ -295,10 +289,10 @@ subprojects { jar { manifest { attributes("Specification-Version": project.version, - "Specification-Vendor": "Apache", + "Specification-Vendor": "WeBank, Inc.", "Specification-Title": project.name, "Implementation-Version": project.version, - "Implementation-Vendor": "Apache", + "Implementation-Vendor": "WeBank, Inc.", "Implementation-Title": project.name, "Build-Jdk": project.findProperty("jdk") ) @@ -325,7 +319,7 @@ subprojects { } copy { into '../dist/lib' - from project.configurations.runtime + from project.configurations.runtimeClasspath exclude '**/*.properties*' exclude '**/*testng*.jar' exclude '**/*powermock*.jar' @@ -383,12 +377,6 @@ subprojects { } } - signing { - sign packageJavadoc, packageSources, jar - } - - - repositories { maven { url "https://maven.aliyun.com/repository/public" } mavenCentral() @@ -401,56 +389,62 @@ subprojects { resolutionStrategy.cacheDynamicVersionsFor 0, TimeUnit.SECONDS } - - uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { - MavenDeployment deployment -> signing.signPom(deployment) - } - // 指定上传的路径 - def releaseRepo = 'https://repository.apache.org/content/repositories/releases/' - def snapshotsRepo = 'https://repository.apache.org/content/repositories/snapshots/' - repository(url: releaseRepo) { - authentication(userName: apacheUserName, password: apachePassWord) - } - - snapshotRepository(url: snapshotsRepo) { - authentication(userName: apacheUserName, password: apachePassWord) - } - - - pom.project { - name 'Apache EventMesh' - packaging 'jar' - // optionally artifactId can be defined here - description 'Apache EventMesh' - url 'https://github.com/apache/incubator-eventmesh' - - scm { - connection 'scm:git:git@github.com:apache/incubator-eventmesh.git' - developerConnection 'scm:git:git@github.com:apache/incubator-eventmesh.git' - url 'https://github.com/apache/incubator-eventmesh' + publishing { + publications { + mavenJava(MavenPublication) { + from components.java + artifact packageSources + artifact packageJavadoc + versionMapping { + usage('java-api') { + fromResolutionOf('runtimeClasspath') } - + usage('java-runtime') { + fromResolutionResult() + } + } + pom { + name = 'EventMesh' + description = 'Apache EventMesh' + url = 'https://github.com/apache/incubator-eventmesh' licenses { license { - name 'The Apache License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } - developers { developer { - id 'Apache EventMesh(incubating)' - name 'Apache EventMesh(incubating) of ASF' - url 'https://eventmesh.apache.org/' + id = 'Apache EventMesh(incubating)' + name = 'Apache EventMesh(incubating) of ASF' + url = 'https://eventmesh.apache.org/' } } + scm { + connection = 'scm:git:git@github.com:apache/incubator-eventmesh.git' + developerConnection = 'scm:git:git@github.com:apache/incubator-eventmesh.git' + url = 'https://github.com/apache/incubator-eventmesh' + } + } + } + } + repositories { + maven { + def releasesRepoUrl = 'https://repository.apache.org/content/repositories/releases/' + def snapshotsRepoUrl = 'https://repository.apache.org/content/repositories/snapshots/' + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + credentials { + username apacheUserName + password apachePassWord } + } } } + signing { + sign publishing.publications.mavenJava + } + } diff --git a/docker/centos7-jdk8/Dockerfile b/docker/centos7-jdk8/Dockerfile index 546d3247fc..7d968413d5 100644 --- a/docker/centos7-jdk8/Dockerfile +++ b/docker/centos7-jdk8/Dockerfile @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + FROM docker.io/centos:7 MAINTAINER mikexue diff --git a/docker/eventmesh-rocketmq/Dockerfile b/docker/eventmesh-rocketmq/Dockerfile index 326cee133d..5b61cc4f5d 100644 --- a/docker/eventmesh-rocketmq/Dockerfile +++ b/docker/eventmesh-rocketmq/Dockerfile @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + FROM centos7-jdk8:latest MAINTAINER mikexue mike_xwm@126.com diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 1f6bad1330..870c593b08 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + module.exports = { title: 'EventMesh', description: 'EventMesh', diff --git a/docs/README.md b/docs/README.md index 9e8b030a18..5909122319 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,9 @@ -[![Build Status](https://www.travis-ci.org/WeBankFinTech/DeFiBus.svg?branch=master)](https://www.travis-ci.org/WeBankFinTech/EventMesh) -[![Coverage Status](https://coveralls.io/repos/github/WeBankFinTech/DeFiBus/badge.svg?branch=master)](https://coveralls.io/github/WeBankFinTech/EventMesh?branch=master) -[![GitHub release](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/WeBankFinTech/EventMesh/releases) +# Apache EventMesh (Incubating) +[![CI status](https://github.com/apache/incubator-eventmesh/actions/workflows/ci.yml/badge.svg)](https://github.com/apache/incubator-eventmesh/actions/workflows/ci.yml) +[![CodeCov](https://codecov.io/gh/apache/incubator-eventmesh/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/incubator-eventmesh) +[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/apache/incubator-eventmesh.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/incubator-eventmesh/context:java) +[![Total alerts](https://img.shields.io/lgtm/alerts/g/apache/incubator-eventmesh.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/incubator-eventmesh/alerts/) +[![GitHub release](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/apache/incubator-eventmesh/releases) [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) [点我查看中文版](cn/README.md) @@ -63,13 +66,13 @@ Key components: 1. Build and deploy event-store(RocketMQ), see [instruction](https://rocketmq.apache.org/docs/quick-start/). 2. Build and deploy eventmesh-runtime, see - instruction ['eventmesh-runtime quickstart'](instructions/eventmesh-runtime-quickstart.md). + instruction ['eventmesh-runtime quickstart'](en/instructions/eventmesh-runtime-quickstart.md). 3. Run eventmesh-sdk-java demo, see - instruction ['eventmesh-sdk-java quickstart'](instructions/eventmesh-sdk-java-quickstart.md). + instruction ['eventmesh-sdk-java quickstart'](en/instructions/eventmesh-sdk-java-quickstart.md). ## Contributing -Contributions are always welcomed! Please see [CONTRIBUTING](CONTRIBUTING.md) for detailed guidelines +Contributions are always welcomed! Please see [CONTRIBUTING](../CONTRIBUTING.md) for detailed guidelines You can start with the issues labeled with good first issue. [GitHub Issues](https://github.com/WeBankFinTech/EventMesh/issues) diff --git a/docs/_config.yml b/docs/_config.yml index c4192631f2..3ef20c109c 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1 +1,20 @@ -theme: jekyll-theme-cayman \ No newline at end of file +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +theme: jekyll-theme-cayman diff --git a/docs/cn/README.md b/docs/cn/README.md index 8b19f4de3b..3aae2a3726 100644 --- a/docs/cn/README.md +++ b/docs/cn/README.md @@ -1,6 +1,9 @@ -[![Build Status](https://www.travis-ci.org/WeBankFinTech/DeFiBus.svg?branch=master)](https://www.travis-ci.org/WeBankFinTech/EventMesh) -[![Coverage Status](https://coveralls.io/repos/github/WeBankFinTech/DeFiBus/badge.svg?branch=master)](https://coveralls.io/github/WeBankFinTech/EventMesh?branch=master) -[![GitHub release](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/WeBankFinTech/EventMesh/releases) +# Apache EventMesh (Incubating) +[![CI status](https://github.com/apache/incubator-eventmesh/actions/workflows/ci.yml/badge.svg)](https://github.com/apache/incubator-eventmesh/actions/workflows/ci.yml) +[![CodeCov](https://codecov.io/gh/apache/incubator-eventmesh/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/incubator-eventmesh) +[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/apache/incubator-eventmesh.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/incubator-eventmesh/context:java) +[![Total alerts](https://img.shields.io/lgtm/alerts/g/apache/incubator-eventmesh.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/incubator-eventmesh/alerts/) +[![GitHub release](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/apache/incubator-eventmesh/releases) [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) ## 什么是Event Mesh? @@ -56,15 +59,15 @@ Event Mesh允许将来自一个应用程序的事件动态路由到任何其他 ## 快速开始 1. 构建并部署event-store(RocketMQ), 请参见[说明](https://rocketmq.apache.org/docs/quick-start/) -2. 构建并部署eventmesh-runtime,请参见说明['eventmesh-runtime quickstart']( instructions/eventmesh-runtime-quickstart.md) -3. 运行eventmesh-sdk-java演示,请参见说明['eventmesh-sdk-java quickstart'](instructions/eventmesh-sdk-java-quickstart.md) +2. 构建并部署eventmesh-runtime,请参见说明['eventmesh-runtime quickstart'](instructions/eventmesh-runtime-quickstart.zh-CN.md) +3. 运行eventmesh-sdk-java演示,请参见说明['eventmesh-sdk-java quickstart'](instructions/eventmesh-sdk-java-quickstart.zh-CN.md) ## 贡献 -永远欢迎参与共建, 请参阅[贡献](CONTRIBUTING.md)了解详细指南 +永远欢迎参与共建, 请参阅[贡献](../../CONTRIBUTING.zh-CN.md)了解详细指南 您可以从问题开始. -[GitHub Issues](https://github.com/WeBankFinTech/EventMesh/issues) +[GitHub Issues](https://github.com/apache/incubator-eventmesh/issues) ## License diff --git a/docs/cn/features/0-introduction.md b/docs/cn/features/0-introduction.md deleted file mode 100644 index 7df673178a..0000000000 --- a/docs/cn/features/0-introduction.md +++ /dev/null @@ -1,56 +0,0 @@ -# DeFiBus - -       -** -DeFiBus=RPC+MQ,是基于开源消息中间件打造的安全可靠的分布式金融级消息总线。DeFibus不仅提供了RPC同步调用,还提供了MQ的异步事件通知、事件组播和广播等常用服务调用和消息模式,同时增加了应用多中心多活、服务就近、灰度发布等分布式场景下的高可用能力。在对于机器故障的容错能力方面的增强,也让消息总线的服务更加稳定可靠,为业务提供7x24的服务。** - -### 整体架构 - -
- -![architecture1](../../../docs/images/features/a-distributing-architecture-in-financial.png) - -
- -![architecture2](../../../docs/images/features/architecture-p1.png) - -DeFiBus主要包括以下几个组件(模块): - -* **Broker**:通过轻量的Topic和Queue机制提供消息存储功能。Broker定期将Topic信息上报到NameServer中,同集群中的Broker实例上报的NameServer必须保持一致,避免路由信息不一致。 - -* **NameServer**:NameServer提供Topic的发现和路由,每一个NameServer接受Broker上报的Topic信息,并维护Topic的路由信息供客户端查询。 - -* **GSL**:全局服务定位(Global Service - Location)服务提供服务级别的路由发现。服务可以部署在不同的区域(比如不同的数据中心、逻辑分区等),服务请求方在请求某一个具体服务时,无需关注服务部署的区域,GSL能够根据服务发现规则自动定位到具体的服务,将服务信息返回给客户端。 - -* **SGS**:服务治理系统(Service Government - System)负责全局的服务管理,包括服务的申请、服务部署规划、服务下线等服务全生命周期的管理。在DeFiBus中,服务与Topic一一对应,Topic的名称由对应的服务按照一定的规则来命名。Topic的创建、更新和删除由SGS统一管理。SGS在服务的部署区域对应的Broker集群中创建Topic之后,将更新全局服务路由数据,供GSL定位服务使用。 - -* **EventMesh**:服务代理(EventMesh)提供HTTP接入方式,同时允许按照协议规范开发的C、GO、Python等其他语言客户端的接入。 - -### 服务和Topic的定义 - -       -DeFiBus把服务和Topic做了一一对应,每个服务必须对应一个Topic。Topic根据服务的唯一ID和服务的部署区域来命名。每个服务需要有服务的唯一标识,可以用数字ID或者字符串来表示。每个部署区域使用3位长度的字符串(限数字和字母构成)表示。 -Topic按照如下格式来命名: - -``` -[区域代码]-[服务唯一ID] -``` - -比如,余额查询服务的服务ID为20190001表示,部署在“A10”这个区域,那么该服务在A10区域的Topic就命名为“A10-20190001”。Topic的命名规则 - -### 特性列表: - -* [RPC调用:即“Request-Reply”模式,支持系统间的同步调用](docs/cn/features/1-request-response-call.md) -* 消息发布/订阅:消息的发布和订阅 -* [灰度发布:服务级别的灰度发布](docs/cn/features/2-dark-launch.md) -* [熔断机制:应用实例级别的熔断](docs/cn/features/3-circuit-break-mechanism.md) -* [服务就近:就近进行服务的请求和响应,减少跨区调用](docs/cn/features/4-invoke-service-nearby.md) -* [应用多活:应用多中心多活](docs/cn/features/5-multi-active.md) -* [动态扩缩队列 :自适应应用实例数量,动态调整队列个数](docs/cn/features/6-dynamic-adjust-queue.md) -* [容错机制:故障和错误隔离](docs/cn/features/8-fault-tolerant.md) -* 服务路由和定位:动态路由及定位(后续开源) -* 服务代理:HTTP及多语言的代理(后续开源) -* 服务治理:服务元数据的管理(后续开源) -* 平滑升级:平滑升级、平滑扩容(后续开源) \ No newline at end of file diff --git a/docs/cn/features/1-request-response-call.md b/docs/cn/features/1-request-response-call.md deleted file mode 100644 index 10166d74ef..0000000000 --- a/docs/cn/features/1-request-response-call.md +++ /dev/null @@ -1,34 +0,0 @@ -## 1. Request-Reply同步调用 - -       Request-Reply同步调用指的是请求方发出一条消息之后,需要响应方在消费完这条消息后回复一个响应结果。 - -
- -![RR](../../images/features/RR-call-p1.png) - -
- -整个调用过程包含了两个消息的产生和消费过程。 -**1.请求方产生请求消息,服务响应方消费这条请求消息** -       请求方根据服务提供方的协议将请求内容设置到消息体中,并将消息发送到Broker上。服务响应方订阅相应的Topic,从Broker上获取到请求消息,并消费。 - -**2.服务响应方产生响应消息,请求方接收这条响应消息** -       -服务响应方收到请求消息后,执行相应的处理,并将请求结果设置到响应消息的消息体中,将响应消息发送到Broker上。请求方接收响应消息的方式采用的是Broker推送的形式,而不是由Producer订阅的方式,从而使得响应消息能够精准回到发出请求消息的实例上。 - -       -DeFiBus在每条请求消息中增加REPLY_TO属性来唯一标识每一个请求方实例。在创建响应消息时将REPLY_TO属性透传到响应消息中。Broker收到响应消息后,根据REPLY_TO属性,查找出对应的请求方实例的连接,将响应消息推送给该请求方实例。 - - ---- - -#### Links: - -* [架构介绍](../../../README.md) -* [Request-Reply调用](docs/cn/features/1-request-response-call.md) -* [灰度发布](docs/cn/features/2-dark-launch.md) -* [熔断机制](docs/cn/features/3-circuit-break-mechanism.md) -* [服务就近](docs/cn/features/4-invoke-service-nearby.md) -* [应用多活](docs/cn/features/5-multi-active.md) -* [动态扩缩队列](docs/cn/features/6-dynamic-adjust-queue.md) -* [容错机制](docs/cn/features/8-fault-tolerant.md) \ No newline at end of file diff --git a/docs/cn/features/10-flow-control.md b/docs/cn/features/10-flow-control.md deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/docs/cn/features/2-dark-launch.md b/docs/cn/features/2-dark-launch.md deleted file mode 100644 index 148838614e..0000000000 --- a/docs/cn/features/2-dark-launch.md +++ /dev/null @@ -1,26 +0,0 @@ -## 2.灰度发布 - -       -同一个消费组中的消费者实例通常订阅的Topic是相同的。在有新业务上线时,我们希望仅仅在个别实例上进行灰度,验证通过之后再进行全量。DeFiBus提供了灰度发布的能力,同一个消费组中,允许不同消费者实例订阅不同的Topic,只有订阅了某个具体Topic的实例才能够收到这个Topic的消息,同消费组中没有订阅这个Topic的实例不会收到消息。 - -       -假设一个消费组有3个消费者实例,上线初期只涉及到Topic1和Topic2。当业务扩展,需要增加Topic3的订阅时,可以先灰度其中一个实例,验证Topic3在灰度实例上执行正常之后,逐步再替换其他实例。在这期间,实例1和实例2不会收到Topic3的消息。 - -
- -![avater](../../images/features/dark-launch-p1.png) - -
- ---- - -#### Links: - -* [架构介绍](../../../README.md) -* [Request-Reply调用](docs/cn/features/1-request-response-call.md) -* [灰度发布](docs/cn/features/2-dark-launch.md) -* [熔断机制](docs/cn/features/3-circuit-break-mechanism.md) -* [服务就近](docs/cn/features/4-invoke-service-nearby.md) -* [应用多活](docs/cn/features/5-multi-active.md) -* [动态扩缩队列](docs/cn/features/6-dynamic-adjust-queue.md) -* [容错机制](docs/cn/features/8-fault-tolerant.md) \ No newline at end of file diff --git a/docs/cn/features/3-circuit-break-mechanism.md b/docs/cn/features/3-circuit-break-mechanism.md deleted file mode 100644 index 3ae2f7a635..0000000000 --- a/docs/cn/features/3-circuit-break-mechanism.md +++ /dev/null @@ -1,28 +0,0 @@ -## 3.熔断 - -       -DeFiBus基于队列来做消费端的负载均衡,对同一个消费组,除广播模式外,每个队列只由一个消费者实例消费。当一个实例处理能力下降或者异常出现消息堆积时,为了避免堆积情况继续加剧,DeFiBus会触发队列的熔断,此时生产者实例在感知到队列熔断之后,会优先把消息发送到其他没有熔断的队列上,暂停往熔断队列上写入新消息。当堆积消除后,熔断被解除,生产者恢复往该队列发送消息。 - -       -DeFiBus对每个Topic定义了深度的属性,表示Topic的队列允许堆积的最大消息条数。消息堆积数表示队列中尚未下发给消费者实例的消息条数,可由队列中最新一条消息的offset与消费者实例已经获取到的消息的offset的差值计算。 -
- -![offset](../../../docs/images/features/circuit-break-p1.png) - -
- -       -当Consumer出现异常或者触发了流控,Consumer拉消息过程受阻,队列的DeliverOffset停止不前,新消息持续写入,MaxOffset不断变大,最终MaxOffset与DeliverOffset将超过Topic的最大深度限制,触发队列熔断。 - ---- - -#### Links: - -* [架构介绍](../../../README.md) -* [Request-Reply调用](docs/cn/features/1-request-response-call.md) -* [灰度发布](docs/cn/features/2-dark-launch.md) -* [熔断机制](docs/cn/features/3-circuit-break-mechanism.md) -* [服务就近](docs/cn/features/4-invoke-service-nearby.md) -* [应用多活](docs/cn/features/5-multi-active.md) -* [动态扩缩队列](docs/cn/features/6-dynamic-adjust-queue.md) -* [容错机制](docs/cn/features/8-fault-tolerant.md) diff --git a/docs/cn/features/4-invoke-service-nearby.md b/docs/cn/features/4-invoke-service-nearby.md deleted file mode 100644 index 4a24248fd6..0000000000 --- a/docs/cn/features/4-invoke-service-nearby.md +++ /dev/null @@ -1,34 +0,0 @@ -## 4.服务就近 - -       -为了保证高可用,服务的部署通常分布在多个机房、区域。我们希望服务之间能够就近调用,减少跨机房跨区域网络访问的时延问题。对此,DeFiBus在Broker和客户端上都增加了区域的属性来标识实例属于哪个区域。对于Producer,消息会优先发往同区域内的Broker集群上;对于Consumer,则优先监听同区域内的Queue;当一个区域内没有Consumer实例监听时,则由其他区域的Consumer实例跨区域监听。 - -### 就近发送 - -       在创建Producer时,通过设置```DeFiBusClientConfig.setClusterPrefix("your region")``` -来标识Producer实例所在的区域。Producer在每次发送消息会先选则一个Queue来作为发送的目标队列。当启用就近发送时,Producer优先选择与自己同区域内的Queue,当本区域内没有可用Queue时,则选择其他区域的Queue。 -
- -
- -### 就近监听 - -       -就近监听指的是Consumer在做负载均衡分配Queue的时候,每个区域内的Queue只由该区域内的Consumer监听和消费,当且仅当一个区域内没有订阅该Topic的Consumer时,由其他区域订阅了该Topic的Consumer跨区域监听和消费这些Queue。虽然Consumer是在同区域内就近消费,但仍通过心跳维持跨区域的连接,以保证能够随时跨区域接管消费。 - -
- -
- ---- - -#### Links: - -* [架构介绍](../../../README.md) -* [Request-Reply调用](docs/cn/features/1-request-response-call.md) -* [灰度发布](docs/cn/features/2-dark-launch.md) -* [熔断机制](docs/cn/features/3-circuit-break-mechanism.md) -* [服务就近](docs/cn/features/4-invoke-service-nearby.md) -* [应用多活](docs/cn/features/5-multi-active.md) -* [动态扩缩队列](docs/cn/features/6-dynamic-adjust-queue.md) -* [容错机制](docs/cn/features/8-fault-tolerant.md) \ No newline at end of file diff --git a/docs/cn/features/5-multi-active.md b/docs/cn/features/5-multi-active.md deleted file mode 100644 index 9e19d6d7cc..0000000000 --- a/docs/cn/features/5-multi-active.md +++ /dev/null @@ -1,21 +0,0 @@ -## 5.同城多中心多活 - -       -同城多中心多活指的是应用的多活,在DeFiBus集群正常运行的情况下,应用部署在多个数据中心,一个数据中心的应用实例全部挂掉后,DeFiBus能够自动将应用流量切换到另一个数据中心的应用实例上,保证应用能够持续稳定地提供服务而不中断。同城多中心多活得益于DeFiBus的服务就近特性,结合应用部署的规划,使得正常情况下服务调用发生在同一个数据中心,当一个中心的应用出现故障时,能够有其他中心的实例接管服务。 - -
- -
- ---- - -#### Links: - -* [架构介绍](../../../README.md) -* [Request-Reply调用](docs/cn/features/1-request-response-call.md) -* [灰度发布](docs/cn/features/2-dark-launch.md) -* [熔断机制](docs/cn/features/3-circuit-break-mechanism.md) -* [服务就近](docs/cn/features/4-invoke-service-nearby.md) -* [应用多活](docs/cn/features/5-multi-active.md) -* [动态扩缩队列](docs/cn/features/6-dynamic-adjust-queue.md) -* [容错机制](docs/cn/features/8-fault-tolerant.md) \ No newline at end of file diff --git a/docs/cn/features/6-dynamic-adjust-queue.md b/docs/cn/features/6-dynamic-adjust-queue.md deleted file mode 100644 index 287fa7fc54..0000000000 --- a/docs/cn/features/6-dynamic-adjust-queue.md +++ /dev/null @@ -1,38 +0,0 @@ -## 自动伸缩Queue - -       -在同一个消费组内,每个队列只由一个实例消费。当队列数小于消费者实例数时,会有部分消费者实例分不到队列;反之,当队列数大于消费者实例数时,每个消费者需要消费多个队列。队列数不是消费者实例数的整数倍时,则会出现部分实例需要消费比同组内的其他实例更多的队列,出现负载不均衡问题。 - -       -DeFiBus提供了队列数量自动调整的特性。当有Consumer新注册或者去注册时,Broker触发队列的自动伸缩,根据当前在线的消费者实例个数,增加或者减少队列个数,使队列个数与消费者实例数保持一致。 - -       -当队列数需要增加时,首先调整Topic的ReadQueueNum,将可读的队列数扩增;10s之后,再调整Topic的WriteQueueNum,将可写的队列数扩增。这样使得新扩增的队列能够先被消费者感知并监听上,然后才让生产者感知到,往新队列上发送消息,是扩增操作更平滑。 - -
- -
- -       -当队列数需要减少时,首先调整Topic的WriteQueueNum,将可写的队列数缩减;5分钟(默认,可配置)后先检查即将被缩减的队列中是否有消息没有被消费完,如果有,则继续延迟缩减操作,使消费者能够继续消费完队列中的消息;如果没有,则调整ReadQueueNum,将可写的队列数缩减。 - -
- -
- -       -对于多个消费组订阅相同Topic并且是集群消费模式时,在计算扩缩的队列个数时,以最大的消费组的消费者实例数为准,保证拥有最多实例数的消费组内每个消费者实例都能够分到Queue进行消费。 - - ---- - -#### Links: - -* [架构介绍](../../../README.md) -* [Request-Reply调用](docs/cn/features/1-request-response-call.md) -* [灰度发布](docs/cn/features/2-dark-launch.md) -* [熔断机制](docs/cn/features/3-circuit-break-mechanism.md) -* [服务就近](docs/cn/features/4-invoke-service-nearby.md) -* [应用多活](docs/cn/features/5-multi-active.md) -* [动态扩缩队列](docs/cn/features/6-dynamic-adjust-queue.md) -* [容错机制](docs/cn/features/8-fault-tolerant.md) \ No newline at end of file diff --git a/docs/cn/features/7-isolation-mechanism.md b/docs/cn/features/7-isolation-mechanism.md deleted file mode 100644 index 3c86bc9aaf..0000000000 --- a/docs/cn/features/7-isolation-mechanism.md +++ /dev/null @@ -1,26 +0,0 @@ -## 隔离机制 - -Producer在往Topic发送消息时,会按照MessageQueueSelector定义的选择策略,从Topic的所有MessageQueue中选择一个作为目标队列发送消息。 -当队列发生熔断,或者Broker故障导致队列发送消息异常时,如果没有对这些队列进行特殊处理,下次再轮到发这个队列的时候仍然可能失败。 - -DeFiBus提供异常队列的隔离机制,当往某个队列发送消息失败时,将队列标记为隔离状态,在隔离过期之前将不再往这个队列发送消息,避免再次失败,降低失败概率。 - -异常队列隔离机制分为两步: -**-发现并标记队列为隔离** -在发送回调中更新发送队列的健康状态,如果执行的是onSuccess分支,则标记队列为健康,去除队列的隔离标记;如果执行的是onException分支,则标记队列为隔离状态。 - -**-不选择隔离中的队列发送消息** -在MessageQueueSelector中实现隔离机制的过滤逻辑,每次进行队列的选择时,优先从没有标记为隔离的队列中选择。当所有队列都被标记为隔离时,则从所有队列中选择,保证每次都要选出一个队列。 - ---- - -#### Links: - -* [架构介绍](../../../README.md) -* [Request-Reply调用](docs/cn/features/1-request-response-call.md) -* [灰度发布](docs/cn/features/2-dark-launch.md) -* [熔断机制](docs/cn/features/3-circuit-break-mechanism.md) -* [服务就近](docs/cn/features/4-invoke-service-nearby.md) -* [应用多活](docs/cn/features/5-multi-active.md) -* [动态扩缩队列](docs/cn/features/6-dynamic-adjust-queue.md) -* [容错机制](docs/cn/features/8-fault-tolerant.md) \ No newline at end of file diff --git a/docs/cn/features/8-fault-tolerant.md b/docs/cn/features/8-fault-tolerant.md deleted file mode 100644 index 6814e12c34..0000000000 --- a/docs/cn/features/8-fault-tolerant.md +++ /dev/null @@ -1,51 +0,0 @@ -## 8.容错机制 - -       在金融场景下,对可用性和稳定性的要求非常高,中间件对机器故障、网络故障、应用故障以及中间件本身的故障等常见故障场景需要有容错能力,降低故障带来的影响。 - -### 隔离机制 - -##### 1. Producer端的隔离 - -       -Producer在往Topic发送消息时,会按照MessageQueueSelector定义的选择策略,从Topic的所有MessageQueue中选择一个作为目标队列发送消息。 -当队列发生熔断,或者Broker故障导致队列发送消息异常时,如果没有对这些队列进行特殊处理,下次再轮到发这个队列的时候仍然可能失败。 - -       DeFiBus提供异常队列的隔离机制,当往某个队列发送消息失败时,将队列标记为隔离状态,在隔离过期之前将不再往这个队列发送消息,避免再次失败,降低失败概率。 - -异常队列隔离机制分为两步: -**-发现并标记队列为隔离** -       -在发送回调中更新发送队列的健康状态,如果执行的是onSuccess分支,则标记队列为健康,去除队列的隔离标记;如果执行的是onException分支,则标记队列为隔离状态。 - -**-不选择隔离中的队列发送消息** -       -在MessageQueueSelector中实现隔离机制的过滤逻辑,每次进行队列的选择时,优先从没有标记为隔离的队列中选择。当所有队列都被标记为隔离时,则从所有队列中选择,保证每次都要选出一个队列。 - -##### 2. Consumer端的隔离 - -       -Consumer由拉消息线程只负责把拉消息请求以异步发送的形式发送出去。在正常情况下,每次拉消息请求的执行都很快,不会有卡顿。一旦有Broker故障导致PullRequest的执行发生了卡顿,则该Consumer监听的所有Queue都会因为PullRequest执行的延迟而出现消息消费延迟。对于RR同步请求的场景,这种是不能够接受的。 - -       -创建连接采用的是同步建立连接的策略,线程执行创建新连接时必须等待连接创建完成或者连接超时。当有Broker故障连不上时,就算是异步发送,也会因为同步等待连接建立而阻塞。此时就会出现一个Broker的故障导致其他健康Broker的消息消费出现延迟。 - -       -DeFiBus在Consumer拉消息的过程中增加了对拉消息任务的隔离,此处的隔离指的是将疑似有问题的任务隔离到另外的线程中执行,保证拉消息线程能够正常处理其他正常的任务。当发现执行拉消息耗时超过设定的阈值时,将该拉消息任务对应的Broker列入“隔离名单”中,在隔离过期之前,隔离Broker的拉消息请求都转交给另外线程执行,避免阻塞拉消息主线程,从而避免故障的Broker影响健康Broker的消息消费时效。 - -### 连接空闲机制 - -       当连接的读或者写空闲超过60秒时,将主动断开连接。 - - ---- - -#### Links: - -* [架构介绍](../../../README.md) -* [Request-Reply调用](docs/cn/features/1-request-response-call.md) -* [灰度发布](docs/cn/features/2-dark-launch.md) -* [熔断机制](docs/cn/features/3-circuit-break-mechanism.md) -* [服务就近](docs/cn/features/4-invoke-service-nearby.md) -* [应用多活](docs/cn/features/5-multi-active.md) -* [动态扩缩队列](docs/cn/features/6-dynamic-adjust-queue.md) -* [容错机制](docs/cn/features/8-fault-tolerant.md) \ No newline at end of file diff --git a/docs/cn/features/9-publish-type.md b/docs/cn/features/9-publish-type.md deleted file mode 100644 index 18ddd6bfe2..0000000000 --- a/docs/cn/features/9-publish-type.md +++ /dev/null @@ -1,33 +0,0 @@ -## 2. 单播、多播、广播 - -       DeFiBus支持单播、多播、广播消费模式。 - -### 单播 - -
- -![unicast](../../images/features/unicast.png) - -
- -单播模式下,topic只被一个消费组监听;接收消息时,消费组内有且仅有一个实例会收到消息。 - -### 多播 - -
- -![multicast](../../images/features/multicast.png) - -
- -多播模式下,topic被多个消费组监听;接收消息时,每个消费组内有且仅有一个实例会收到消息。 - -### 广播 - -
- -![broadcast](../../images/features/broadcast.png) - -
- -广播模式下,监听此topic的每个消费组中的每个实例都需要收到消息。 \ No newline at end of file diff --git a/docs/cn/features/https.zh-CN.md b/docs/cn/features/https.zh-CN.md index 044e89bf53..fa1244f949 100644 --- a/docs/cn/features/https.zh-CN.md +++ b/docs/cn/features/https.zh-CN.md @@ -9,7 +9,6 @@ config env varible -Dssl.server.protocol=TLSv1.1 //默认值 TLSv1.1 -Dssl.server.cer=sChat2.jks //把文件放到启动脚本start.sh 指定的conPath目录下 -Dssl.server.pass=sNetty - ``` 2.在eventmesh-sdk-java 中配置 diff --git a/docs/cn/instructions/eventmesh-runtime-quickstart.zh-CN.md b/docs/cn/instructions/eventmesh-runtime-quickstart.zh-CN.md index b6bc593603..adc9703796 100644 --- a/docs/cn/instructions/eventmesh-runtime-quickstart.zh-CN.md +++ b/docs/cn/instructions/eventmesh-runtime-quickstart.zh-CN.md @@ -7,7 +7,7 @@ ``` 建议使用64位操作系统,建议使用Linux / Unix; 64位JDK 1.8+; -Gradle至少为5.6, 推荐 5.6.* +Gradle至少为7.0, 推荐 7.0.* ``` ### 1.2 下载源码 @@ -19,7 +19,7 @@ Gradle至少为5.6, 推荐 5.6.* ```$ xslt unzip EventMesh-master.zip -cd / *您的部署路径* /EventMesh-master/eventmesh-runtime +cd / *您的部署路径* /EventMesh-master gradle clean dist tar -x test ``` @@ -68,11 +68,12 @@ sh start.sh **2.3.2 配置VM启动参数** ```java --Dlog4j.configurationFile=..\eventmesh-runtime\conf\log4j2.xml --Deventmesh.log.home=..\eventmesh-runtime\logs --Deventmesh.home=..\eventmesh-runtime --DconfPath=..\eventmesh-runtime\conf +-Dlog4j.configurationFile=eventmesh-runtime/conf/log4j2.xml +-Deventmesh.log.home=eventmesh-runtime/logs +-Deventmesh.home=eventmesh-runtime +-DconfPath=eventmesh-runtime/conf ``` +> 注:如果操作系统为Windows, 可能需要将文件分隔符换成\ **2.3.3 配置build.gradle文件** @@ -190,8 +191,7 @@ docker run -d -p 10911:10911 -p 10909:10909 -v `pwd`/data/broker/logs:/root/logs Windows -- -Windows系统下运行示例可以参考[这里](https://github.com/apache/incubator-eventmesh/blob/develop/docs/cn/instructions/eventmesh-sdk-java-quickstart.zh-CN.md) +- Windows系统下运行示例可以参考[这里](https://github.com/apache/incubator-eventmesh/blob/develop/docs/cn/instructions/eventmesh-sdk-java-quickstart.zh-CN.md) Linux diff --git a/docs/cn/instructions/eventmesh-sdk-java-quickstart.zh-CN.md b/docs/cn/instructions/eventmesh-sdk-java-quickstart.zh-CN.md index 43df03320f..aa5768ac15 100644 --- a/docs/cn/instructions/eventmesh-sdk-java-quickstart.zh-CN.md +++ b/docs/cn/instructions/eventmesh-sdk-java-quickstart.zh-CN.md @@ -16,7 +16,7 @@ TCP 和 Http 示例都在**eventmesh-test**模块下

异步消息

-- 创建主题FT0-e-80010000-01-1,可以通过rocketmq-console或者rocketmq tools 命令 +- 创建主题TEST-TOPIC-TCP-ASYNC,可以通过rocketmq-console或者rocketmq tools 命令 - 启动消费者,订阅上一步骤已经创建的Topic @@ -32,7 +32,7 @@ TCP 和 Http 示例都在**eventmesh-test**模块下

广播消息

-- 创建主题FT0-e-80030000-01-3,可以通过rocketmq-console或者rocketmq tools 命令 +- 创建主题TEST-TOPIC-TCP-BROADCAST,可以通过rocketmq-console或者rocketmq tools 命令 - 启动消费端,订阅上一步骤已经创建的Topic @@ -56,7 +56,7 @@ TCP 和 Http 示例都在**eventmesh-test**模块下 > 生产者将事件发送给下游即可,无需等待响应 -- 创建主题FT0-e-80010001-01-1,可以通过rocketmq-console或者rocketmq tools 命令 +- 创建主题TEST-TOPIC-HTTP-ASYNC,可以通过rocketmq-console或者rocketmq tools 命令 - 启动消费端,订阅Topic diff --git a/docs/cn/instructions/quickstart.zh-CN.md b/docs/cn/instructions/quickstart.zh-CN.md index d5f384075e..e14bf122bf 100644 --- a/docs/cn/instructions/quickstart.zh-CN.md +++ b/docs/cn/instructions/quickstart.zh-CN.md @@ -10,15 +10,15 @@ Gradle至少为5.6, 推荐 5.6.* ### 部署eventmesh-store -阅读更多[这里](eventmesh-store-quickstart.md) +阅读更多[这里](eventmesh-store-quickstart.zh-CN.md) ### 部署eventmesh-runtime -阅读更多[这里](eventmesh-runtime-quickstart.md) +阅读更多[这里](eventmesh-runtime-quickstart.zh-CN.md) ### 运行eventmesh sdk演示 -阅读更多[这里](eventmesh-sdk-java-quickstart.md) +阅读更多[这里](eventmesh-sdk-java-quickstart.zh-CN.md) ### 通信协议 diff --git a/docs/en/README.md b/docs/en/README.md index 254cd2a195..1b8d3c1178 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -1,9 +1,12 @@ -[![Build Status](https://www.travis-ci.org/WeBankFinTech/DeFiBus.svg?branch=master)](https://www.travis-ci.org/WeBankFinTech/EventMesh) -[![Coverage Status](https://coveralls.io/repos/github/WeBankFinTech/DeFiBus/badge.svg?branch=master)](https://coveralls.io/github/WeBankFinTech/EventMesh?branch=master) -[![GitHub release](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/WeBankFinTech/EventMesh/releases) +# Apache EventMesh (Incubating) +[![CI status](https://github.com/apache/incubator-eventmesh/actions/workflows/ci.yml/badge.svg)](https://github.com/apache/incubator-eventmesh/actions/workflows/ci.yml) +[![CodeCov](https://codecov.io/gh/apache/incubator-eventmesh/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/incubator-eventmesh) +[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/apache/incubator-eventmesh.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/incubator-eventmesh/context:java) +[![Total alerts](https://img.shields.io/lgtm/alerts/g/apache/incubator-eventmesh.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/incubator-eventmesh/alerts/) +[![GitHub release](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/apache/incubator-eventmesh/releases) [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) -[点我查看中文版](/cn/README.md) +[点我查看中文版](../cn/README.md) ## What is Event Mesh? @@ -72,10 +75,10 @@ Key components: ## Contributing -Contributions are always welcomed! Please see [CONTRIBUTING](CONTRIBUTING.md) for detailed guidelines +Contributions are always welcomed! Please see [CONTRIBUTING](../../CONTRIBUTING.md) for detailed guidelines You can start with the issues labeled with good first issue. -[GitHub Issues](https://github.com/WeBankFinTech/EventMesh/issues) +[GitHub Issues](https://github.com/apache/incubator-eventmesh/issues) ## License diff --git a/docs/en/features/architecture.md b/docs/en/features/architecture.md deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/docs/en/features/eventmesh-cloudevents-sdk-binding.md b/docs/en/features/eventmesh-cloudevents-sdk-binding.md new file mode 100644 index 0000000000..3c1224f413 --- /dev/null +++ b/docs/en/features/eventmesh-cloudevents-sdk-binding.md @@ -0,0 +1,55 @@ +# Lightweight EventMesh SDK (CloudEvents) + +## Introduction + +[EventMesh(incubating)](https://github.com/apache/incubator-eventmesh) is a dynamic +cloud-native eventing infrastructure. + +[CloudEvents](https://github.com/cloudevents/spec) is a specification for describing +event data in common formats to provide interoperability across services, platforms and systems. + +As of May 2021, EventMesh contains the following +major components: `eventmesh-runtime`, `eventmesh-sdk-java` and `eventmesh-connector-rocketmq`. +For a customer to use EventMesh, `eventmesh-runtime` can be deployed as microservices to transmit +customer's events between event producers and consumers. Customer's applications can then interact +with `eventmesh-runtime` using `eventmesh-sdk-java` to publish/subscribe for events on given topics. + +CloudEvents support has been a highly desired feature by EventMesh users. There are many reasons +for users to prefer using a SDK with CloudEvents support: +- CloudEvents is a more widely accepted and supported way to describe events. `eventmesh-sdk-java` + currently uses the `LiteMessage` structure to describe events, which is less standardized. +- CloudEvents's Java SDK has a wider range of distribution methods. For example, EventMesh users + currently need to use the SDK tarball or build from source for every EventMesh release. With + CloudEvents support, it's easier for users to take a dependency on EventMesh's SDK using CloudEvents's + public distributions (e.g. through a Maven configuration). +- CloudEvents's SDK supports multiple languages. Although EventMesh currently only supports a Java SDK, + in future if more languages need to be supported, the extensions can be easier with experience on + binding Java SDK with CloudEvents. + +## Requirements + +### Functional Requirements + +| Requirement ID | Requirement Description | Comments | +| -------------- | ----------------------- | -------- | +| F-1 | EventMesh users should be able to depend on a public SDK to publish/subscribe events in CloudEvents format | Functionality | +| F-2 | EventMesh users should continue to have access to existing EventMesh client features (e.g. load balancing) with an SDK that supports CloudEvent | Feature Parity | +| F-3 | EventMesh developers should be able to sync `eventmesh-sdk-java` and an SDK with CloudEvents support without much effort/pain | Maintainability | + +### Performance Requirements + +| Requirement ID | Requirement Description | Comments | +| -------------- | ----------------------- | -------- | +| P-1 | Client side latency for SDK with CloudEvents support should be similar to current SDK | | + +## Design Details + +Binding with the CloudEvents Java SDK (similar to what Kafka already did, see Reference for more details) +should be an easy way to achieve the requirements. + +Design details TBD. + +## Appendix + +### References +- https://cloudevents.github.io/sdk-java/kafka diff --git a/docs/en/features/request-response-call.md b/docs/en/features/request-response-call.md deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/docs/en/instructions/eventmesh-runtime-quickstart.md b/docs/en/instructions/eventmesh-runtime-quickstart.md index 3b1e1090ca..0536e5b6ee 100644 --- a/docs/en/instructions/eventmesh-runtime-quickstart.md +++ b/docs/en/instructions/eventmesh-runtime-quickstart.md @@ -7,7 +7,7 @@ ``` 64bit OS, Linux/Unix is recommended; 64bit JDK 1.8+; -Gradle at least 5.6, eg 5.6.* +Gradle at least 7.0, eg 7.0.* ``` ### 1.2 download sources @@ -19,8 +19,8 @@ You will get **EventMesh-master.zip** ```$xslt unzip EventMesh-master.zip -cd /*YOUR DEPLOY PATH*/EventMesh-master/eventmesh-runtime -gradle clean tar -x test +cd /*YOUR DEPLOY PATH*/EventMesh-master +gradle clean dist tar -x test ``` You will get **EventMesh_1.2.0.tar.gz** in directory /* YOUR DEPLOY PATH */EventMesh-master/build @@ -63,17 +63,18 @@ Same with 1.2 - eventmesh-sdk-java : eventmesh java client sdk - eventmesh-starter : eventmesh project local start entry -ps:The loading of connector plugin follows the Java SPI mechanism, it's necessary to configure the mapping file of +> ps: The loading of connector plugin follows the Java SPI mechanism, it's necessary to configure the mapping file of related interface and implementation class under /main/resources/meta-inf/services in the corresponding module **2.3.2 Configure VM Options** ```java --Dlog4j.configurationFile=..\eventmesh-runtime\conf\log4j2.xml --Deventmesh.log.home=..\eventmesh-runtime\logs --Deventmesh.home=..\eventmesh-runtime --DconfPath=..\eventmesh-runtime\conf +-Dlog4j.configurationFile=eventmesh-runtime/conf/log4j2.xml +-Deventmesh.log.home=eventmesh-runtime/logs +-Deventmesh.home=eventmesh-runtime +-DconfPath=eventmesh-runtime/conf ``` +> ps: If you use Windows, you may need to replace the file separator to \ **2.3.3 Configure build.gradle file** diff --git a/docs/en/instructions/eventmesh-sdk-java-quickstart.md b/docs/en/instructions/eventmesh-sdk-java-quickstart.md index a754502aa8..53eb673709 100644 --- a/docs/en/instructions/eventmesh-sdk-java-quickstart.md +++ b/docs/en/instructions/eventmesh-sdk-java-quickstart.md @@ -17,7 +17,7 @@ the `resources` directory #### Async msg -- create topic FT0-e-80010000-01-1 on rocketmq-console +- create topic TEST-TOPIC-TCP-ASYNC on rocketmq-console - start consumer ,subscribe topic in previous step. @@ -33,7 +33,7 @@ Run the main method of org.apache.eventmesh.tcp.demo.AsyncPublish #### Broadcast msg -- create topic FT0-e-80030000-01-3 on rocketmq-console +- create topic TEST-TOPIC-TCP-BROADCAST on rocketmq-console - start consumer ,subscribe topic in previous step. @@ -57,7 +57,7 @@ Run the main method of org.apache.eventmesh.tcp.demo.AsyncPublishBroadcast > producer send the event to consumer and don't need waiting response msg from consumer -- create topic FT0-e-80010001-01-1 on rocketmq-console +- create topic TEST-TOPIC-HTTP-ASYNC on rocketmq-console - start consumer, subscribe topic diff --git a/docs/en/instructions/eventmesh-store-quickstart.md b/docs/en/instructions/eventmesh-store-quickstart.md index b5fd94fbf3..74158e85fc 100644 --- a/docs/en/instructions/eventmesh-store-quickstart.md +++ b/docs/en/instructions/eventmesh-store-quickstart.md @@ -16,7 +16,7 @@ You will get **DefiBus-master.zip** ### build sources -The eventmesh-store takes DeFiBus for example at the follwing parts, because eventmesh depends on defibus as store layer +The eventmesh-store takes DeFiBus for example at the following parts, because eventmesh depends on defibus as store layer by default, other implements such as Rocketmq etc. is coming soon. ``` diff --git a/docs/eventmesh.md b/docs/eventmesh.md index 9460476259..432c09360d 100644 --- a/docs/eventmesh.md +++ b/docs/eventmesh.md @@ -30,7 +30,7 @@ EventMesh允许将来自一个应用程序的事件动态路由到任何其他 ## 开源地址 * https://github.com/WeBankFinTech/DeFiBus -* https://github.com/WeBankFinTech/EventMesh +* https://github.com/apache/incubator-eventmesh * https://gitee.com/WeBank/DeFiBus * https://gitee.com/WeBank/EventMesh diff --git a/docs/images/eventmesh-panels.png b/docs/images/eventmesh-panels.png index 7abab98814..898dbb42ba 100644 Binary files a/docs/images/eventmesh-panels.png and b/docs/images/eventmesh-panels.png differ diff --git a/docs/images/eventmesh-runtime.png b/docs/images/eventmesh-runtime.png index b826c12a15..a87a8d6908 100644 Binary files a/docs/images/eventmesh-runtime.png and b/docs/images/eventmesh-runtime.png differ diff --git a/docs/images/logo1.png b/docs/images/logo1.png new file mode 100644 index 0000000000..00cba89e08 Binary files /dev/null and b/docs/images/logo1.png differ diff --git a/docs/images/logo2.png b/docs/images/logo2.png new file mode 100644 index 0000000000..248020806c Binary files /dev/null and b/docs/images/logo2.png differ diff --git a/eventmesh-common/gradle.properties b/eventmesh-common/gradle.properties index 1f92fb3dfc..72ea1ac35b 100644 --- a/eventmesh-common/gradle.properties +++ b/eventmesh-common/gradle.properties @@ -15,5 +15,5 @@ # limitations under the License. # group=org.apache.eventmesh -version=1.2.0 +version=1.2.0-release jdk=1.8 diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/Constants.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/Constants.java index 937859a8b4..c2457addc6 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/Constants.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/Constants.java @@ -21,10 +21,6 @@ public class Constants { public static final String DEFAULT_CHARSET = "UTF-8"; - public static final String TARGET_EVENTMESH_REGION = "TARGET_EVENTMESH_REGION"; - - public static final String CONSTANTS_DEFAULT_REGION_KEY = "default"; - public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; public static final String LANGUAGE_JAVA = "JAVA"; @@ -47,8 +43,6 @@ public class Constants { public static final String CONSTANTS_INSTANCE_DESC_IDC = "idc"; - public static final String CONSTANTS_INSTANCE_DESC_DCN = "dcn"; - public static final String CONSTANTS_INSTANCE_DESC_SYSID = "sysId"; public static final String CONSTANTS_INSTANCE_DESC_IP = "ip"; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/IPUtil.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/IPUtil.java index 4cd19e4f3b..5165deb8af 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/IPUtil.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/IPUtil.java @@ -35,7 +35,7 @@ public class IPUtil { public static String getLocalAddress() { // if the progress works under docker environment // return the host ip about this docker located from environment value - String dockerHostIp = System.getenv("webank_docker_host_ip"); + String dockerHostIp = System.getenv("docker_host_ip"); if (dockerHostIp != null && !"".equals(dockerHostIp)) return dockerHostIp; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/command/HttpCommand.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/command/HttpCommand.java index 31179562af..d36a1ae613 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/command/HttpCommand.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/command/HttpCommand.java @@ -17,19 +17,9 @@ package org.apache.eventmesh.common.command; -import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; - import com.alibaba.fastjson.JSON; - import io.netty.buffer.Unpooled; -import io.netty.handler.codec.http.DefaultFullHttpResponse; -import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaderValues; -import io.netty.handler.codec.http.HttpHeaders; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpVersion; - +import io.netty.handler.codec.http.*; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; @@ -38,6 +28,9 @@ import org.apache.eventmesh.common.protocol.http.header.BaseResponseHeader; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; + public class HttpCommand { private static AtomicLong requestId = new AtomicLong(0); diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java index 931f41bf99..08a44cb8e1 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java @@ -31,9 +31,7 @@ public class CommonConfiguration { public String eventMeshEnv = "P"; - public String eventMeshRegion = ""; public String eventMeshIDC = "FT"; - public String eventMeshDCN = "1C0"; public String eventMeshCluster = "LS"; public String eventMeshName = ""; public String sysID = "5477"; @@ -68,10 +66,6 @@ public void init() { Preconditions.checkState(StringUtils.isNotEmpty(eventMeshEnvStr), String.format("%s error", ConfKeys.KEYS_EVENTMESH_ENV)); eventMeshEnv = StringUtils.deleteWhitespace(eventMeshEnvStr); - String eventMeshRegionStr = configurationWraper.getProp(ConfKeys.KEYS_EVENTMESH_REGION); - Preconditions.checkState(StringUtils.isNotEmpty(eventMeshRegionStr), String.format("%s error", ConfKeys.KEYS_EVENTMESH_REGION)); - eventMeshRegion = StringUtils.deleteWhitespace(eventMeshRegionStr); - String sysIdStr = configurationWraper.getProp(ConfKeys.KEYS_EVENTMESH_SYSID); Preconditions.checkState(StringUtils.isNotEmpty(sysIdStr) && StringUtils.isNumeric(sysIdStr), String.format("%s error", ConfKeys.KEYS_EVENTMESH_SYSID)); sysID = StringUtils.deleteWhitespace(sysIdStr); @@ -88,10 +82,6 @@ public void init() { Preconditions.checkState(StringUtils.isNotEmpty(eventMeshIDCStr), String.format("%s error", ConfKeys.KEYS_EVENTMESH_IDC)); eventMeshIDC = StringUtils.deleteWhitespace(eventMeshIDCStr); - String eventMeshDCNStr = configurationWraper.getProp(ConfKeys.KEYS_EVENTMESH_DCN); - Preconditions.checkState(StringUtils.isNotEmpty(eventMeshDCNStr), String.format("%s error", ConfKeys.KEYS_EVENTMESH_DCN)); - eventMeshDCN = StringUtils.deleteWhitespace(eventMeshDCNStr); - eventMeshServerIp = configurationWraper.getProp(ConfKeys.KEYS_EVENTMESH_SERVER_HOST_IP); if (StringUtils.isBlank(eventMeshServerIp)) { eventMeshServerIp = getLocalAddr(); @@ -102,12 +92,8 @@ public void init() { static class ConfKeys { public static String KEYS_EVENTMESH_ENV = "eventMesh.server.env"; - public static String KEYS_EVENTMESH_REGION = "eventMesh.server.region"; - public static String KEYS_EVENTMESH_IDC = "eventMesh.server.idc"; - public static String KEYS_EVENTMESH_DCN = "eventMesh.server.dcn"; - public static String KEYS_EVENTMESH_SYSID = "eventMesh.sysid"; public static String KEYS_EVENTMESH_SERVER_CLUSTER = "eventMesh.server.cluster"; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/LoadBalanceSelector.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/LoadBalanceSelector.java new file mode 100644 index 0000000000..3bee08c6ec --- /dev/null +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/LoadBalanceSelector.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.common.loadbalance; + +/** + * LoadBalance Interface + * + *

see {@link RandomLoadBalanceSelector} + *

see {@link WeightRoundRobinLoadBalanceSelector} + * + * @param Target type + */ +public interface LoadBalanceSelector { + + /** + * Select one + * + * @return target + */ + T select(); + + /** + * load balance type see {@link LoadBalanceType} + * + * @return load balance type of the selector + */ + LoadBalanceType getType(); + +} diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/LoadBalanceType.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/LoadBalanceType.java new file mode 100644 index 0000000000..858a69b1c6 --- /dev/null +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/LoadBalanceType.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.eventmesh.common.loadbalance; + +public enum LoadBalanceType { + RANDOM(0, "random load balance strategy"), + WEIGHT_ROUND_ROBIN(1, "weight round robin load balance strategy"); + + private int code; + private String desc; + + LoadBalanceType(int code, String desc) { + this.code = code; + this.desc = desc; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + +} diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelector.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelector.java new file mode 100644 index 0000000000..fc741a5a82 --- /dev/null +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelector.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.common.loadbalance; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.RandomUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +/** + * This selector use random strategy. + * Each selection will randomly give one from the given list + * + * @param + */ +public class RandomLoadBalanceSelector implements LoadBalanceSelector { + + private final Logger logger = LoggerFactory.getLogger(RandomLoadBalanceSelector.class); + + private final List clusterGroup; + + public RandomLoadBalanceSelector(List clusterGroup) { + this.clusterGroup = clusterGroup; + } + + @Override + public T select() { + if (CollectionUtils.isEmpty(clusterGroup)) { + logger.warn("No servers available"); + return null; + } + return clusterGroup.get(RandomUtils.nextInt(0, clusterGroup.size())); + } + + @Override + public LoadBalanceType getType() { + return LoadBalanceType.RANDOM; + } +} diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/Weight.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/Weight.java new file mode 100644 index 0000000000..e793955c5c --- /dev/null +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/Weight.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.common.loadbalance; + +import java.util.concurrent.atomic.AtomicInteger; + +public class Weight { + + private T target; + + private final int weight; + + private final AtomicInteger currentWeight; + + public Weight(T target, int weight) { + this.target = target; + this.weight = weight; + this.currentWeight = new AtomicInteger(0); + } + + public void decreaseTotal(int total) { + currentWeight.addAndGet(-1 * total); + } + + public void increaseCurrentWeight() { + currentWeight.addAndGet(weight); + } + + + public T getTarget() { + return target; + } + + public void setTarget(T target) { + this.target = target; + } + + public int getWeight() { + return weight; + } + + + public AtomicInteger getCurrentWeight() { + return currentWeight; + } + + @Override + public String toString() { + return "Wight{" + + "target=" + target + + ", weight=" + weight + + ", currentWeight=" + currentWeight + + '}'; + } +} diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelector.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelector.java new file mode 100644 index 0000000000..d6f2009bf3 --- /dev/null +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelector.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.common.loadbalance; + +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +/** + * This selector use the weighted round robin strategy to select from list. + * If the weight is greater, the probability of being selected is larger. + * + * @param + */ +public class WeightRoundRobinLoadBalanceSelector implements LoadBalanceSelector { + + private final Logger logger = LoggerFactory.getLogger(WeightRoundRobinLoadBalanceSelector.class); + + private final List> clusterGroup; + + private final int totalWeight; + + public WeightRoundRobinLoadBalanceSelector(List> clusterGroup) { + int totalWeight = 0; + for (Weight weight : clusterGroup) { + totalWeight += weight.getWeight(); + } + this.clusterGroup = clusterGroup; + this.totalWeight = totalWeight; + } + + + @Override + @SuppressWarnings("ConstantConditions") + public T select() { + if (CollectionUtils.isEmpty(clusterGroup)) { + logger.warn("No servers available"); + return null; + } + Weight targetWeight = null; + for (Weight weight : clusterGroup) { + weight.increaseCurrentWeight(); + if (targetWeight == null || targetWeight.getCurrentWeight().get() < weight.getCurrentWeight().get()) { + targetWeight = weight; + } + } + targetWeight.decreaseTotal(totalWeight); + return targetWeight.getTarget(); + } + + @Override + public LoadBalanceType getType() { + return LoadBalanceType.WEIGHT_ROUND_ROBIN; + } +} diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubcriptionType.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubcriptionType.java new file mode 100644 index 0000000000..6b6cb16823 --- /dev/null +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubcriptionType.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.common.protocol; + +public enum SubcriptionType { + /** + * SYNC + */ + SYNC("SYNC"), + /** + * ASYNC + */ + ASYNC("ASYNC"); + + private String type; + + SubcriptionType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubscriptionItem.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubscriptionItem.java new file mode 100644 index 0000000000..abcc22c20e --- /dev/null +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubscriptionItem.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.common.protocol; + +public class SubscriptionItem { + + private String topic; + + private SubscriptionMode mode; + + private SubcriptionType type; + + public SubscriptionItem() { + } + + public SubscriptionItem(String topic, SubscriptionMode mode, SubcriptionType type) { + this.topic = topic; + this.mode = mode; + this.type = type; + } + + public SubcriptionType getType() { + return type; + } + + public void setType(SubcriptionType type) { + this.type = type; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public SubscriptionMode getMode() { + return mode; + } + + public void setMode(SubscriptionMode mode) { + this.mode = mode; + } + + @Override + public String toString() { + return "SubscriptionItem{" + + "topic=" + topic + + ", mode=" + mode + + ", type=" + type + + '}'; + } +} + + diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubscriptionMode.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubscriptionMode.java new file mode 100644 index 0000000000..ad4b751a46 --- /dev/null +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubscriptionMode.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.common.protocol; + +public enum SubscriptionMode { + + /** + * broadcast + */ + BROADCASTING("BROADCASTING"), + /** + * clustering + */ + CLUSTERING("CLUSTERING"); + + private String mode; + + SubscriptionMode(String mode) { + this.mode = mode; + } + + public String getMode() { + return mode; + } + + public void setMode(String mode) { + this.mode = mode; + } + +} diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/HeartbeatRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/HeartbeatRequestBody.java index 5c3d1ea09e..751b63248f 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/HeartbeatRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/HeartbeatRequestBody.java @@ -31,7 +31,9 @@ public class HeartbeatRequestBody extends Body { public static final String CLIENTTYPE = "clientType"; public static final String HEARTBEATENTITIES = "heartbeatEntities"; + public static final String CONSUMERGROUP = "consumerGroup"; + private String consumerGroup; private String clientType; @@ -53,9 +55,18 @@ public void setHeartbeatEntities(List heartbeatEntities) { this.heartbeatEntities = heartbeatEntities; } + public String getConsumerGroup() { + return consumerGroup; + } + + public void setConsumerGroup(String consumerGroup) { + this.consumerGroup = consumerGroup; + } + public static HeartbeatRequestBody buildBody(Map bodyParam) { HeartbeatRequestBody body = new HeartbeatRequestBody(); body.setClientType(MapUtils.getString(bodyParam, CLIENTTYPE)); + body.setConsumerGroup(MapUtils.getString(bodyParam, CONSUMERGROUP)); body.setHeartbeatEntities(JSONArray.parseArray(MapUtils.getString(bodyParam, HEARTBEATENTITIES), HeartbeatEntity.class)); return body; } @@ -64,6 +75,7 @@ public static HeartbeatRequestBody buildBody(Map bodyParam) { public Map toMap() { Map map = new HashMap(); map.put(CLIENTTYPE, clientType); + map.put(CONSUMERGROUP, consumerGroup); map.put(HEARTBEATENTITIES, JSON.toJSONString(heartbeatEntities)); return map; } @@ -90,6 +102,7 @@ public String toString() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("heartbeatRequestBody={") + .append("consumerGroup=").append(consumerGroup).append(",") .append("clientType=").append(clientType).append("}"); return sb.toString(); } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/RegRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/RegRequestBody.java index 41c5c5ab98..78bb684cbd 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/RegRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/RegRequestBody.java @@ -25,6 +25,7 @@ import com.alibaba.fastjson.JSONArray; import org.apache.commons.collections4.MapUtils; +import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.http.body.Body; public class RegRequestBody extends Body { @@ -39,13 +40,13 @@ public class RegRequestBody extends Body { private String endPoint; - private List topics; + private List topics; - public List getTopics() { + public List getTopics() { return topics; } - public void setTopics(List topics) { + public void setTopics(List topics) { this.topics = topics; } @@ -69,7 +70,7 @@ public static RegRequestBody buildBody(Map bodyParam) { RegRequestBody body = new RegRequestBody(); body.setClientType(MapUtils.getString(bodyParam, CLIENTTYPE)); body.setEndPoint(MapUtils.getString(bodyParam, ENDPOINT)); - body.setTopics(JSONArray.parseArray(MapUtils.getString(bodyParam, TOPICS), String.class)); + body.setTopics(JSONArray.parseArray(MapUtils.getString(bodyParam, TOPICS), SubscriptionItem.class)); return body; } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/SubscribeRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/SubscribeRequestBody.java index 6a37cc53d2..72e2e91aab 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/SubscribeRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/SubscribeRequestBody.java @@ -25,6 +25,7 @@ import com.alibaba.fastjson.JSONArray; import org.apache.commons.collections4.MapUtils; +import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.http.body.Body; public class SubscribeRequestBody extends Body { @@ -33,17 +34,27 @@ public class SubscribeRequestBody extends Body { public static final String URL = "url"; - private List topics; + public static final String CONSUMERGROUP = "consumerGroup"; + + private List topics; private String url; - private String topic; + private String consumerGroup; + + public String getConsumerGroup() { + return consumerGroup; + } + + public void setConsumerGroup(String consumerGroup) { + this.consumerGroup = consumerGroup; + } - public List getTopics() { + public List getTopics() { return topics; } - public void setTopics(List topics) { + public void setTopics(List topics) { this.topics = topics; } @@ -58,7 +69,8 @@ public void setUrl(String url) { public static SubscribeRequestBody buildBody(Map bodyParam) { SubscribeRequestBody body = new SubscribeRequestBody(); body.setUrl(MapUtils.getString(bodyParam, URL)); - body.setTopics(JSONArray.parseArray(MapUtils.getString(bodyParam, TOPIC), String.class)); + body.setTopics(JSONArray.parseArray(MapUtils.getString(bodyParam, TOPIC), SubscriptionItem.class)); + body.setConsumerGroup(MapUtils.getString(bodyParam, CONSUMERGROUP)); return body; } @@ -67,13 +79,15 @@ public Map toMap() { Map map = new HashMap(); map.put(URL, url); map.put(TOPIC, JSON.toJSONString(topics)); + map.put(CONSUMERGROUP, consumerGroup); return map; } @Override public String toString() { return "subscribeBody{" + - "url='" + url + '\'' + + "consumerGroup='" + consumerGroup + '\'' + + ", url='" + url + '\'' + ", topics=" + topics + '}'; } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnSubscribeRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnSubscribeRequestBody.java index e690f7e599..756f1a92e4 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnSubscribeRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnSubscribeRequestBody.java @@ -33,10 +33,14 @@ public class UnSubscribeRequestBody extends Body { public static final String URL = "url"; + public static final String CONSUMERGROUP = "consumerGroup"; + private List topics; private String url; + private String consumerGroup; + public List getTopics() { return topics; } @@ -53,10 +57,19 @@ public void setUrl(String url) { this.url = url; } + public String getConsumerGroup() { + return consumerGroup; + } + + public void setConsumerGroup(String consumerGroup) { + this.consumerGroup = consumerGroup; + } + public static UnSubscribeRequestBody buildBody(Map bodyParam) { UnSubscribeRequestBody body = new UnSubscribeRequestBody(); body.setUrl(MapUtils.getString(bodyParam, URL)); body.setTopics(JSONArray.parseArray(MapUtils.getString(bodyParam, TOPIC), String.class)); + body.setConsumerGroup(MapUtils.getString(bodyParam, CONSUMERGROUP)); return body; } @@ -65,13 +78,15 @@ public Map toMap() { Map map = new HashMap(); map.put(URL, url); map.put(TOPIC, JSON.toJSONString(topics)); + map.put(CONSUMERGROUP, consumerGroup); return map; } @Override public String toString() { return "unSubscribeRequestBody{" + - "url='" + url + '\'' + + "consumerGroup='" + consumerGroup + '\'' + + ", url='" + url + '\'' + ", topics=" + topics + '}'; } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/ReplyMessageRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/ReplyMessageRequestBody.java index ddd29e5a6d..e2de019df4 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/ReplyMessageRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/ReplyMessageRequestBody.java @@ -29,12 +29,12 @@ public class ReplyMessageRequestBody extends Body { - public static final String ORIGTOPIC = "origTopic"; public static final String BIZSEQNO = "bizSeqNo"; public static final String UNIQUEID = "uniqueId"; public static final String CONTENT = "content"; public static final String EXTFIELDS = "extFields"; + public static final String PRODUCERGROUP = "producerGroup"; private String bizSeqNo; @@ -46,6 +46,8 @@ public class ReplyMessageRequestBody extends Body { private HashMap extFields; + private String producerGroup; + public String getOrigTopic() { return origTopic; } @@ -86,6 +88,14 @@ public void setExtFields(HashMap extFields) { this.extFields = extFields; } + public String getProducerGroup() { + return producerGroup; + } + + public void setProducerGroup(String producerGroup) { + this.producerGroup = producerGroup; + } + @SuppressWarnings("unchecked") public static ReplyMessageRequestBody buildBody(Map bodyParam) { ReplyMessageRequestBody body = new ReplyMessageRequestBody(); @@ -97,6 +107,7 @@ public static ReplyMessageRequestBody buildBody(Map bodyParam) { if (StringUtils.isNotBlank(extFields)) { body.setExtFields((HashMap) JSONObject.parseObject(extFields, HashMap.class)); } + body.setProducerGroup(MapUtils.getString(bodyParam, PRODUCERGROUP)); return body; } @@ -108,6 +119,7 @@ public String toString() { .append("uniqueId=").append(uniqueId).append(",") .append("origTopic=").append(origTopic).append(",") .append("content=").append(content).append(",") + .append("producerGroup=").append(producerGroup).append(",") .append("extFields=").append(extFields).append("}"); return sb.toString(); } @@ -120,6 +132,7 @@ public Map toMap() { map.put(UNIQUEID, uniqueId); map.put(CONTENT, content); map.put(EXTFIELDS, JSON.toJSONString(extFields)); + map.put(PRODUCERGROUP, producerGroup); return map; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchRequestBody.java index ced6bef3c5..576e35224c 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchRequestBody.java @@ -33,6 +33,7 @@ public class SendMessageBatchRequestBody extends Body { public static final String BATCHID = "batchId"; public static final String CONTENTS = "contents"; public static final String SIZE = "size"; + public static final String PRODUCERGROUP = "producerGroup"; private String batchId; @@ -40,6 +41,8 @@ public class SendMessageBatchRequestBody extends Body { private String size; + private String producerGroup; + public SendMessageBatchRequestBody() { } @@ -67,12 +70,21 @@ public void setSize(String size) { this.size = size; } + public String getProducerGroup() { + return producerGroup; + } + + public void setProducerGroup(String producerGroup) { + this.producerGroup = producerGroup; + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("sendMessageBatchRequestBody={") .append("batchId=").append(batchId).append(",") .append("size=").append(size).append(",") + .append("producerGroup=").append(producerGroup).append(",") .append("contents=").append(JSON.toJSONString(contents)).append("}"); return sb.toString(); } @@ -111,6 +123,7 @@ public static SendMessageBatchRequestBody buildBody(final Map bo body.setContents(JSONArray.parseArray(contents, BatchMessageEntity.class)); } body.setSize(size); + body.setProducerGroup(MapUtils.getString(bodyParam, PRODUCERGROUP)); return body; } @@ -120,6 +133,7 @@ public Map toMap() { map.put(BATCHID, batchId); map.put(SIZE, size); map.put(CONTENTS, contents); + map.put(PRODUCERGROUP, producerGroup); return map; } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchV2RequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchV2RequestBody.java index dc46adc92b..8f97cf16c0 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchV2RequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchV2RequestBody.java @@ -30,6 +30,7 @@ public class SendMessageBatchV2RequestBody extends Body { public static final String MSG = "msg"; public static final String TAG = "tag"; public static final String TTL = "ttl"; + public static final String PRODUCERGROUP = "producerGroup"; private String bizSeqNo; @@ -41,6 +42,8 @@ public class SendMessageBatchV2RequestBody extends Body { private String ttl; + private String producerGroup; + public String getBizSeqNo() { return bizSeqNo; } @@ -81,6 +84,14 @@ public void setTtl(String ttl) { this.ttl = ttl; } + public String getProducerGroup() { + return producerGroup; + } + + public void setProducerGroup(String producerGroup) { + this.producerGroup = producerGroup; + } + public static SendMessageBatchV2RequestBody buildBody(final Map bodyParam) { String bizSeqno = MapUtils.getString(bodyParam, BIZSEQNO); @@ -98,6 +109,7 @@ public static SendMessageBatchV2RequestBody buildBody(final Map body.setTag(tag); body.setTtl(ttl); body.setTopic(topic); + body.setProducerGroup(MapUtils.getString(bodyParam, PRODUCERGROUP)); return body; } @@ -109,6 +121,7 @@ public Map toMap() { map.put(MSG, msg); map.put(TAG, tag); map.put(TTL, ttl); + map.put(PRODUCERGROUP, producerGroup); return map; } @@ -120,6 +133,7 @@ public String toString() { .append("topic=").append(topic).append(",") .append("tag=").append(tag).append(",") .append("ttl=").append(ttl).append(",") + .append("producerGroup=").append(producerGroup).append(",") .append("msg=").append(msg).append("}"); return sb.toString(); } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageRequestBody.java index 840e2f7804..5c302e857c 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageRequestBody.java @@ -35,7 +35,7 @@ public class SendMessageRequestBody extends Body { public static final String TTL = "ttl"; public static final String TAG = "tag"; public static final String EXTFIELDS = "extFields"; - + public static final String PRODUCERGROUP = "producerGroup"; private String topic; @@ -51,6 +51,8 @@ public class SendMessageRequestBody extends Body { private HashMap extFields; + private String producerGroup; + public String getTopic() { return topic; } @@ -107,6 +109,14 @@ public void setTag(String tag) { this.tag = tag; } + public String getProducerGroup() { + return producerGroup; + } + + public void setProducerGroup(String producerGroup) { + this.producerGroup = producerGroup; + } + @SuppressWarnings("unchecked") public static SendMessageRequestBody buildBody(Map bodyParam) { SendMessageRequestBody body = new SendMessageRequestBody(); @@ -120,6 +130,7 @@ public static SendMessageRequestBody buildBody(Map bodyParam) { if (StringUtils.isNotBlank(extFields)) { body.setExtFields((HashMap) JSONObject.parseObject(extFields, HashMap.class)); } + body.setProducerGroup(MapUtils.getString(bodyParam, PRODUCERGROUP)); return body; } @@ -133,6 +144,7 @@ public Map toMap() { map.put(TAG, tag); map.put(CONTENT, content); map.put(EXTFIELDS, extFields); + map.put(PRODUCERGROUP, producerGroup); return map; } @@ -146,6 +158,7 @@ public String toString() { .append("content=").append(content).append(",") .append("ttl=").append(ttl).append(",") .append("tag=").append(tag).append(",") + .append("producerGroup=").append(producerGroup).append(",") .append("extFields=").append(extFields).append("}"); return sb.toString(); } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/ProtocolKey.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/ProtocolKey.java index c6cb15d4dd..12e79ad30d 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/ProtocolKey.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/ProtocolKey.java @@ -26,9 +26,7 @@ public class ProtocolKey { public static class ClientInstanceKey { ////////////////////////////////////协议层请求方描述/////////// public static final String ENV = "Env"; - public static final String REGION = "Region"; public static final String IDC = "Idc"; - public static final String DCN = "Dcn"; public static final String SYS = "Sys"; public static final String PID = "Pid"; public static final String IP = "Ip"; @@ -42,9 +40,7 @@ public static class EventMeshInstanceKey { public static final String EVENTMESHCLUSTER = "EventMeshCluster"; public static final String EVENTMESHIP = "EventMeshIp"; public static final String EVENTMESHENV = "EventMeshEnv"; - public static final String EVENTMESHREGION = "EventMeshRegion"; public static final String EVENTMESHIDC = "EventMeshIdc"; - public static final String EVENTMESHDCN = "EventMeshDcn"; } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatRequestHeader.java index e189823151..5cd07242e2 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatRequestHeader.java @@ -41,15 +41,9 @@ public class HeartbeatRequestHeader extends Header { //请求方所在环境编号 private String env; - //请求方所在区域编码 - private String region; - //请求方所在IDC private String idc; - //请求方所在DCN - private String dcn; - //请求方的子系统 private String sys; @@ -59,6 +53,8 @@ public class HeartbeatRequestHeader extends Header { //请求方的IP private String ip; + private String producerGroup; + //请求方的USERNAME private String username = "username"; @@ -97,14 +93,6 @@ public void setEnv(String env) { this.env = env; } - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - public String getIdc() { return idc; } @@ -113,14 +101,6 @@ public void setIdc(String idc) { this.idc = idc; } - public String getDcn() { - return dcn; - } - - public void setDcn(String dcn) { - this.dcn = dcn; - } - public String getSys() { return sys; } @@ -168,9 +148,7 @@ public Map toMap() { map.put(ProtocolKey.LANGUAGE, language); map.put(ProtocolKey.VERSION, version); map.put(ProtocolKey.ClientInstanceKey.ENV, env); - map.put(ProtocolKey.ClientInstanceKey.REGION, region); map.put(ProtocolKey.ClientInstanceKey.IDC, idc); - map.put(ProtocolKey.ClientInstanceKey.DCN, dcn); map.put(ProtocolKey.ClientInstanceKey.SYS, sys); map.put(ProtocolKey.ClientInstanceKey.PID, pid); map.put(ProtocolKey.ClientInstanceKey.IP, ip); @@ -187,9 +165,7 @@ public String toString() { .append("language=").append(language).append(",") .append("version=").append(version).append(",") .append("env=").append(env).append(",") - .append("region=").append(region).append(",") .append("idc=").append(idc).append(",") - .append("dcn=").append(dcn).append(",") .append("sys=").append(sys).append(",") .append("pid=").append(pid).append(",") .append("ip=").append(ip).append(",") @@ -206,9 +182,7 @@ public static HeartbeatRequestHeader buildHeader(Map headerParam ? Constants.LANGUAGE_JAVA : MapUtils.getString(headerParam, ProtocolKey.LANGUAGE); header.setLanguage(lan); header.setEnv(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.ENV)); - header.setRegion(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.REGION)); header.setIdc(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IDC)); - header.setDcn(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.DCN)); header.setSys(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.SYS)); header.setPid(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.PID)); header.setIp(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IP)); diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatResponseHeader.java index 3863498392..e0d6e99a17 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatResponseHeader.java @@ -34,12 +34,8 @@ public class HeartbeatResponseHeader extends Header { private String eventMeshEnv; - private String eventMeshRegion; - private String eventMeshIdc; - private String eventMeshDcn; - public int getCode() { return code; } @@ -72,14 +68,6 @@ public void setEventMeshEnv(String eventMeshEnv) { this.eventMeshEnv = eventMeshEnv; } - public String getEventMeshRegion() { - return eventMeshRegion; - } - - public void setEventMeshRegion(String eventMeshRegion) { - this.eventMeshRegion = eventMeshRegion; - } - public String getEventMeshIdc() { return eventMeshIdc; } @@ -88,24 +76,14 @@ public void setEventMeshIdc(String eventMeshIdc) { this.eventMeshIdc = eventMeshIdc; } - public String getEventMeshDcn() { - return eventMeshDcn; - } - - public void setEventMeshDcn(String eventMeshDcn) { - this.eventMeshDcn = eventMeshDcn; - } - public static HeartbeatResponseHeader buildHeader(Integer requestCode, String eventMeshCluster, - String eventMeshIp, String eventMeshEnv, String eventMeshRegion, - String eventMeshDcn, String eventMeshIDC) { + String eventMeshIp, String eventMeshEnv, + String eventMeshIDC) { HeartbeatResponseHeader heartbeatResponseHeader = new HeartbeatResponseHeader(); heartbeatResponseHeader.setCode(requestCode); heartbeatResponseHeader.setEventMeshCluster(eventMeshCluster); - heartbeatResponseHeader.setEventMeshDcn(eventMeshDcn); heartbeatResponseHeader.setEventMeshIp(eventMeshIp); heartbeatResponseHeader.setEventMeshEnv(eventMeshEnv); - heartbeatResponseHeader.setEventMeshRegion(eventMeshRegion); heartbeatResponseHeader.setEventMeshIdc(eventMeshIDC); return heartbeatResponseHeader; } @@ -116,9 +94,7 @@ public String toString() { sb.append("heartbeatResponseHeader={") .append("code=").append(code).append(",") .append("eventMeshEnv=").append(eventMeshEnv).append(",") - .append("eventMeshRegion=").append(eventMeshRegion).append(",") .append("eventMeshIdc=").append(eventMeshIdc).append(",") - .append("eventMeshDcn=").append(eventMeshDcn).append(",") .append("eventMeshCluster=").append(eventMeshCluster).append(",") .append("eventMeshIp=").append(eventMeshIp).append("}"); return sb.toString(); @@ -131,9 +107,7 @@ public Map toMap() { map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER, eventMeshCluster); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, eventMeshIp); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, eventMeshEnv); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHREGION, eventMeshRegion); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, eventMeshIdc); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHDCN, eventMeshDcn); return map; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeader.java index 2dbcd6f094..0ee7cab899 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeader.java @@ -37,12 +37,8 @@ public class RegRequestHeader extends Header { private String env; - private String region; - private String idc; - private String dcn; - private String sys; private String pid; @@ -61,9 +57,7 @@ public static RegRequestHeader buildHeader(Map headerParam) { ? Constants.LANGUAGE_JAVA : MapUtils.getString(headerParam, ProtocolKey.LANGUAGE); header.setLanguage(lan); header.setEnv(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.ENV)); - header.setRegion(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.REGION)); header.setIdc(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IDC)); - header.setDcn(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.DCN)); header.setSys(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.SYS)); header.setPid(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.PID)); header.setIp(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IP)); @@ -104,14 +98,6 @@ public void setEnv(String env) { this.env = env; } - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - public String getIdc() { return idc; } @@ -120,14 +106,6 @@ public void setIdc(String idc) { this.idc = idc; } - public String getDcn() { - return dcn; - } - - public void setDcn(String dcn) { - this.dcn = dcn; - } - public String getSys() { return sys; } @@ -175,9 +153,7 @@ public Map toMap() { map.put(ProtocolKey.LANGUAGE, language); map.put(ProtocolKey.VERSION, version); map.put(ProtocolKey.ClientInstanceKey.ENV, env); - map.put(ProtocolKey.ClientInstanceKey.REGION, region); map.put(ProtocolKey.ClientInstanceKey.IDC, idc); - map.put(ProtocolKey.ClientInstanceKey.DCN, dcn); map.put(ProtocolKey.ClientInstanceKey.SYS, sys); map.put(ProtocolKey.ClientInstanceKey.PID, pid); map.put(ProtocolKey.ClientInstanceKey.IP, ip); @@ -194,9 +170,7 @@ public String toString() { .append("language=").append(language).append(",") .append("version=").append(version).append(",") .append("env=").append(env).append(",") - .append("region=").append(region).append(",") .append("idc=").append(idc).append(",") - .append("dcn=").append(dcn).append(",") .append("sys=").append(sys).append(",") .append("pid=").append(pid).append(",") .append("ip=").append(ip).append(",") diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegResponseHeader.java index d0257cc9d6..503a527ea1 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegResponseHeader.java @@ -38,15 +38,9 @@ public class RegResponseHeader extends Header { //处理该次Request请求的eventMesh所在的环境编号 private String eventMeshEnv; - //处理该次Request请求的eventMesh所在区域 - private String eventMeshRegion; - //处理该次Request请求的eventMesh所在IDC private String eventMeshIdc; - //处理该次Request请求的eventMesh所在DCN - private String eventMeshDcn; - public int getCode() { return code; } @@ -79,14 +73,6 @@ public void setEventMeshEnv(String eventMeshEnv) { this.eventMeshEnv = eventMeshEnv; } - public String getEventMeshRegion() { - return eventMeshRegion; - } - - public void setEventMeshRegion(String eventMeshRegion) { - this.eventMeshRegion = eventMeshRegion; - } - public String getEventMeshIdc() { return eventMeshIdc; } @@ -95,24 +81,13 @@ public void setEventMeshIdc(String eventMeshIdc) { this.eventMeshIdc = eventMeshIdc; } - public String getEventMeshDcn() { - return eventMeshDcn; - } - - public void setEventMeshDcn(String eventMeshDcn) { - this.eventMeshDcn = eventMeshDcn; - } - public static RegResponseHeader buildHeader(Integer requestCode, String eventMeshCluster, - String eventMeshIp, String eventMeshEnv, String eventMeshRegion, - String eventMeshDcn, String eventMeshIDC) { + String eventMeshIp, String eventMeshEnv, String eventMeshIDC) { RegResponseHeader regResponseHeader = new RegResponseHeader(); regResponseHeader.setCode(requestCode); regResponseHeader.setEventMeshCluster(eventMeshCluster); - regResponseHeader.setEventMeshDcn(eventMeshDcn); regResponseHeader.setEventMeshIp(eventMeshIp); regResponseHeader.setEventMeshEnv(eventMeshEnv); - regResponseHeader.setEventMeshRegion(eventMeshRegion); regResponseHeader.setEventMeshIdc(eventMeshIDC); return regResponseHeader; } @@ -123,9 +98,7 @@ public String toString() { sb.append("regResponseHeader={") .append("code=").append(code).append(",") .append("eventMeshEnv=").append(eventMeshEnv).append(",") - .append("eventMeshRegion=").append(eventMeshRegion).append(",") .append("eventMeshIdc=").append(eventMeshIdc).append(",") - .append("eventMeshDcn=").append(eventMeshDcn).append(",") .append("eventMeshCluster=").append(eventMeshCluster).append(",") .append("eventMeshIp=").append(eventMeshIp).append("}"); return sb.toString(); @@ -138,9 +111,7 @@ public Map toMap() { map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER, eventMeshCluster); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, eventMeshIp); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, eventMeshEnv); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHREGION, eventMeshRegion); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, eventMeshIdc); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHDCN, eventMeshDcn); return map; } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeader.java index 9fffa22f2e..6143e4b4bc 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeader.java @@ -37,12 +37,8 @@ public class SubscribeRequestHeader extends Header { private String env; - private String region; - private String idc; - private String dcn; - private String sys; private String pid; @@ -61,9 +57,7 @@ public static SubscribeRequestHeader buildHeader(Map headerParam ? Constants.LANGUAGE_JAVA : MapUtils.getString(headerParam, ProtocolKey.LANGUAGE); header.setLanguage(lan); header.setEnv(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.ENV)); - header.setRegion(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.REGION)); header.setIdc(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IDC)); - header.setDcn(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.DCN)); header.setSys(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.SYS)); header.setPid(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.PID)); header.setIp(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IP)); @@ -104,14 +98,6 @@ public void setEnv(String env) { this.env = env; } - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - public String getIdc() { return idc; } @@ -120,14 +106,6 @@ public void setIdc(String idc) { this.idc = idc; } - public String getDcn() { - return dcn; - } - - public void setDcn(String dcn) { - this.dcn = dcn; - } - public String getSys() { return sys; } @@ -175,9 +153,7 @@ public Map toMap() { map.put(ProtocolKey.LANGUAGE, language); map.put(ProtocolKey.VERSION, version); map.put(ProtocolKey.ClientInstanceKey.ENV, env); - map.put(ProtocolKey.ClientInstanceKey.REGION, region); map.put(ProtocolKey.ClientInstanceKey.IDC, idc); - map.put(ProtocolKey.ClientInstanceKey.DCN, dcn); map.put(ProtocolKey.ClientInstanceKey.SYS, sys); map.put(ProtocolKey.ClientInstanceKey.PID, pid); map.put(ProtocolKey.ClientInstanceKey.IP, ip); @@ -194,9 +170,7 @@ public String toString() { .append("language=").append(language).append(",") .append("version=").append(version).append(",") .append("env=").append(env).append(",") - .append("region=").append(region).append(",") .append("idc=").append(idc).append(",") - .append("dcn=").append(dcn).append(",") .append("sys=").append(sys).append(",") .append("pid=").append(pid).append(",") .append("ip=").append(ip).append(",") diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeResponseHeader.java index dbd9bb0241..f21fbceb89 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeResponseHeader.java @@ -33,12 +33,8 @@ public class SubscribeResponseHeader extends Header { private String eventMeshEnv; - private String eventMeshRegion; - private String eventMeshIdc; - private String eventMeshDcn; - public int getCode() { return code; } @@ -71,14 +67,6 @@ public void setEventMeshEnv(String eventMeshEnv) { this.eventMeshEnv = eventMeshEnv; } - public String getEventMeshRegion() { - return eventMeshRegion; - } - - public void setEventMeshRegion(String eventMeshRegion) { - this.eventMeshRegion = eventMeshRegion; - } - public String getEventMeshIdc() { return eventMeshIdc; } @@ -87,24 +75,14 @@ public void setEventMeshIdc(String eventMeshIdc) { this.eventMeshIdc = eventMeshIdc; } - public String getEventMeshDcn() { - return eventMeshDcn; - } - - public void setEventMeshDcn(String eventMeshDcn) { - this.eventMeshDcn = eventMeshDcn; - } - public static SubscribeResponseHeader buildHeader(Integer requestCode, String eventMeshCluster, - String eventMeshIp, String eventMeshEnv, String eventMeshRegion, - String eventMeshDcn, String eventMeshIDC) { + String eventMeshIp, String eventMeshEnv, + String eventMeshIDC) { SubscribeResponseHeader subscribeResponseHeader = new SubscribeResponseHeader(); subscribeResponseHeader.setCode(requestCode); subscribeResponseHeader.setEventMeshCluster(eventMeshCluster); - subscribeResponseHeader.setEventMeshDcn(eventMeshDcn); subscribeResponseHeader.setEventMeshIp(eventMeshIp); subscribeResponseHeader.setEventMeshEnv(eventMeshEnv); - subscribeResponseHeader.setEventMeshRegion(eventMeshRegion); subscribeResponseHeader.setEventMeshIdc(eventMeshIDC); return subscribeResponseHeader; } @@ -115,9 +93,7 @@ public String toString() { sb.append("subscribeResponseHeader={") .append("code=").append(code).append(",") .append("eventMeshEnv=").append(eventMeshEnv).append(",") - .append("eventMeshRegion=").append(eventMeshRegion).append(",") .append("eventMeshIdc=").append(eventMeshIdc).append(",") - .append("eventMeshDcn=").append(eventMeshDcn).append(",") .append("eventMeshCluster=").append(eventMeshCluster).append(",") .append("eventMeshIp=").append(eventMeshIp).append("}"); return sb.toString(); @@ -131,8 +107,6 @@ public Map toMap() { map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, eventMeshIp); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, eventMeshEnv); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, eventMeshIdc); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHREGION, eventMeshRegion); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHDCN, eventMeshDcn); return map; } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegRequestHeader.java index 9e040d234f..09c3a6d378 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegRequestHeader.java @@ -41,15 +41,9 @@ public class UnRegRequestHeader extends Header { //请求方所在环境编号 private String env; - //请求方所在区域编码 - private String region; - //请求方所在IDC private String idc; - //请求方所在DCN - private String dcn; - //请求方的子系统 private String sys; @@ -73,9 +67,7 @@ public static UnRegRequestHeader buildHeader(Map headerParam) { ? Constants.LANGUAGE_JAVA : MapUtils.getString(headerParam, ProtocolKey.LANGUAGE); header.setLanguage(lan); header.setEnv(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.ENV)); - header.setRegion(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.REGION)); header.setIdc(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IDC)); - header.setDcn(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.DCN)); header.setSys(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.SYS)); header.setPid(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.PID)); header.setIp(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IP)); @@ -116,14 +108,6 @@ public void setEnv(String env) { this.env = env; } - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - public String getIdc() { return idc; } @@ -132,14 +116,6 @@ public void setIdc(String idc) { this.idc = idc; } - public String getDcn() { - return dcn; - } - - public void setDcn(String dcn) { - this.dcn = dcn; - } - public String getSys() { return sys; } @@ -187,9 +163,7 @@ public Map toMap() { map.put(ProtocolKey.LANGUAGE, language); map.put(ProtocolKey.VERSION, version); map.put(ProtocolKey.ClientInstanceKey.ENV, env); - map.put(ProtocolKey.ClientInstanceKey.REGION, region); map.put(ProtocolKey.ClientInstanceKey.IDC, idc); - map.put(ProtocolKey.ClientInstanceKey.DCN, dcn); map.put(ProtocolKey.ClientInstanceKey.SYS, sys); map.put(ProtocolKey.ClientInstanceKey.PID, pid); map.put(ProtocolKey.ClientInstanceKey.IP, ip); @@ -206,9 +180,7 @@ public String toString() { .append("language=").append(language).append(",") .append("version=").append(version).append(",") .append("env=").append(env).append(",") - .append("region=").append(region).append(",") .append("idc=").append(idc).append(",") - .append("dcn=").append(dcn).append(",") .append("sys=").append(sys).append(",") .append("pid=").append(pid).append(",") .append("ip=").append(ip).append(",") diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegResponseHeader.java index d009228421..4338c0305f 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegResponseHeader.java @@ -34,12 +34,8 @@ public class UnRegResponseHeader extends Header { private String eventMeshEnv; - private String eventMeshRegion; - private String eventMeshIdc; - private String eventMeshDcn; - public int getCode() { return code; } @@ -72,14 +68,6 @@ public void setEventMeshEnv(String eventMeshEnv) { this.eventMeshEnv = eventMeshEnv; } - public String getEventMeshRegion() { - return eventMeshRegion; - } - - public void setEventMeshRegion(String eventMeshRegion) { - this.eventMeshRegion = eventMeshRegion; - } - public String getEventMeshIdc() { return eventMeshIdc; } @@ -88,24 +76,13 @@ public void setEventMeshIdc(String eventMeshIdc) { this.eventMeshIdc = eventMeshIdc; } - public String getEventMeshDcn() { - return eventMeshDcn; - } - - public void setEventMeshDcn(String eventMeshDcn) { - this.eventMeshDcn = eventMeshDcn; - } - public static UnRegResponseHeader buildHeader(Integer requestCode, String eventMeshCluster, - String eventMeshIp, String eventMeshEnv, String eventMeshRegion, - String eventMeshDcn, String eventMeshIDC) { + String eventMeshIp, String eventMeshEnv, String eventMeshIDC) { UnRegResponseHeader regResponseHeader = new UnRegResponseHeader(); regResponseHeader.setCode(requestCode); regResponseHeader.setEventMeshCluster(eventMeshCluster); - regResponseHeader.setEventMeshDcn(eventMeshDcn); regResponseHeader.setEventMeshIp(eventMeshIp); regResponseHeader.setEventMeshEnv(eventMeshEnv); - regResponseHeader.setEventMeshRegion(eventMeshRegion); regResponseHeader.setEventMeshIdc(eventMeshIDC); return regResponseHeader; } @@ -116,9 +93,7 @@ public String toString() { sb.append("nnRegResponseHeader={") .append("code=").append(code).append(",") .append("eventMeshEnv=").append(eventMeshEnv).append(",") - .append("eventMeshRegion=").append(eventMeshRegion).append(",") .append("eventMeshIdc=").append(eventMeshIdc).append(",") - .append("eventMeshDcn=").append(eventMeshDcn).append(",") .append("eventMeshCluster=").append(eventMeshCluster).append(",") .append("eventMeshIp=").append(eventMeshIp).append("}"); return sb.toString(); @@ -132,8 +107,6 @@ public Map toMap() { map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, eventMeshIp); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, eventMeshEnv); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, eventMeshIdc); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHREGION, eventMeshRegion); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHDCN, eventMeshDcn); return map; } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeader.java index 0c505eef2b..f5b34564ac 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeader.java @@ -37,12 +37,8 @@ public class UnSubscribeRequestHeader extends Header { private String env; - private String region; - private String idc; - private String dcn; - private String sys; private String pid; @@ -61,9 +57,7 @@ public static UnSubscribeRequestHeader buildHeader(Map headerPar ? Constants.LANGUAGE_JAVA : MapUtils.getString(headerParam, ProtocolKey.LANGUAGE); header.setLanguage(lan); header.setEnv(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.ENV)); - header.setRegion(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.REGION)); header.setIdc(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IDC)); - header.setDcn(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.DCN)); header.setSys(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.SYS)); header.setPid(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.PID)); header.setIp(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IP)); @@ -104,14 +98,6 @@ public void setEnv(String env) { this.env = env; } - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - public String getIdc() { return idc; } @@ -120,14 +106,6 @@ public void setIdc(String idc) { this.idc = idc; } - public String getDcn() { - return dcn; - } - - public void setDcn(String dcn) { - this.dcn = dcn; - } - public String getSys() { return sys; } @@ -175,9 +153,7 @@ public Map toMap() { map.put(ProtocolKey.LANGUAGE, language); map.put(ProtocolKey.VERSION, version); map.put(ProtocolKey.ClientInstanceKey.ENV, env); - map.put(ProtocolKey.ClientInstanceKey.REGION, region); map.put(ProtocolKey.ClientInstanceKey.IDC, idc); - map.put(ProtocolKey.ClientInstanceKey.DCN, dcn); map.put(ProtocolKey.ClientInstanceKey.SYS, sys); map.put(ProtocolKey.ClientInstanceKey.PID, pid); map.put(ProtocolKey.ClientInstanceKey.IP, ip); @@ -194,9 +170,7 @@ public String toString() { .append("language=").append(language).append(",") .append("version=").append(version).append(",") .append("env=").append(env).append(",") - .append("region=").append(region).append(",") .append("idc=").append(idc).append(",") - .append("dcn=").append(dcn).append(",") .append("sys=").append(sys).append(",") .append("pid=").append(pid).append(",") .append("ip=").append(ip).append(",") diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeResponseHeader.java index f6e15be3e1..f2638234d2 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeResponseHeader.java @@ -33,12 +33,8 @@ public class UnSubscribeResponseHeader extends Header { private String eventMeshEnv; - private String eventMeshRegion; - private String eventMeshIdc; - private String eventMeshDcn; - public int getCode() { return code; } @@ -71,14 +67,6 @@ public void setEventMeshEnv(String eventMeshEnv) { this.eventMeshEnv = eventMeshEnv; } - public String getEventMeshRegion() { - return eventMeshRegion; - } - - public void setEventMeshRegion(String eventMeshRegion) { - this.eventMeshRegion = eventMeshRegion; - } - public String getEventMeshIdc() { return eventMeshIdc; } @@ -87,24 +75,13 @@ public void setEventMeshIdc(String eventMeshIdc) { this.eventMeshIdc = eventMeshIdc; } - public String getEventMeshDcn() { - return eventMeshDcn; - } - - public void setEventMeshDcn(String eventMeshDcn) { - this.eventMeshDcn = eventMeshDcn; - } - public static UnSubscribeResponseHeader buildHeader(Integer requestCode, String eventMeshCluster, - String eventMeshIp, String eventMeshEnv, String eventMeshRegion, - String eventMeshDcn, String eventMeshIDC) { + String eventMeshIp, String eventMeshEnv, String eventMeshIDC) { UnSubscribeResponseHeader unSubscribeResponseHeader = new UnSubscribeResponseHeader(); unSubscribeResponseHeader.setCode(requestCode); unSubscribeResponseHeader.setEventMeshCluster(eventMeshCluster); - unSubscribeResponseHeader.setEventMeshDcn(eventMeshDcn); unSubscribeResponseHeader.setEventMeshIp(eventMeshIp); unSubscribeResponseHeader.setEventMeshEnv(eventMeshEnv); - unSubscribeResponseHeader.setEventMeshRegion(eventMeshRegion); unSubscribeResponseHeader.setEventMeshIdc(eventMeshIDC); return unSubscribeResponseHeader; } @@ -115,9 +92,7 @@ public String toString() { sb.append("unSubscribeResponseHeader={") .append("code=").append(code).append(",") .append("eventMeshEnv=").append(eventMeshEnv).append(",") - .append("eventMeshRegion=").append(eventMeshRegion).append(",") .append("eventMeshIdc=").append(eventMeshIdc).append(",") - .append("eventMeshDcn=").append(eventMeshDcn).append(",") .append("eventMeshCluster=").append(eventMeshCluster).append(",") .append("eventMeshIp=").append(eventMeshIp).append("}"); return sb.toString(); @@ -131,8 +106,6 @@ public Map toMap() { map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, eventMeshIp); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, eventMeshEnv); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, eventMeshIdc); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHREGION, eventMeshRegion); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHDCN, eventMeshDcn); return map; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeader.java index e0b3fa9f01..18f6cfc659 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeader.java @@ -44,12 +44,8 @@ public class PushMessageRequestHeader extends Header { private String eventMeshEnv; - private String eventMeshRegion; - private String eventMeshIdc; - private String eventMeshDcn; - public int getCode() { return code; } @@ -82,14 +78,6 @@ public void setEventMeshEnv(String eventMeshEnv) { this.eventMeshEnv = eventMeshEnv; } - public String getEventMeshRegion() { - return eventMeshRegion; - } - - public void setEventMeshRegion(String eventMeshRegion) { - this.eventMeshRegion = eventMeshRegion; - } - public String getEventMeshIdc() { return eventMeshIdc; } @@ -98,14 +86,6 @@ public void setEventMeshIdc(String eventMeshIdc) { this.eventMeshIdc = eventMeshIdc; } - public String getEventMeshDcn() { - return eventMeshDcn; - } - - public void setEventMeshDcn(String eventMeshDcn) { - this.eventMeshDcn = eventMeshDcn; - } - public String getLanguage() { return language; } @@ -129,9 +109,7 @@ public static PushMessageRequestHeader buildHeader(final Map hea pushMessageRequestHeader.setVersion(ProtocolVersion.get(MapUtils.getString(headerParam, ProtocolKey.VERSION))); pushMessageRequestHeader.setEventMeshCluster(MapUtils.getString(headerParam, ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER)); pushMessageRequestHeader.setEventMeshIp(MapUtils.getString(headerParam, ProtocolKey.EventMeshInstanceKey.EVENTMESHIP)); - pushMessageRequestHeader.setEventMeshDcn(MapUtils.getString(headerParam, ProtocolKey.EventMeshInstanceKey.EVENTMESHDCN)); pushMessageRequestHeader.setEventMeshEnv(MapUtils.getString(headerParam, ProtocolKey.EventMeshInstanceKey.EVENTMESHENV)); - pushMessageRequestHeader.setEventMeshRegion(MapUtils.getString(headerParam, ProtocolKey.EventMeshInstanceKey.EVENTMESHREGION)); pushMessageRequestHeader.setEventMeshIdc(MapUtils.getString(headerParam, ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC)); return pushMessageRequestHeader; } @@ -145,9 +123,7 @@ public Map toMap() { map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER, eventMeshCluster); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, eventMeshIp); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, eventMeshEnv); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHREGION, eventMeshRegion); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, eventMeshIdc); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHDCN, eventMeshDcn); return map; } @@ -159,9 +135,7 @@ public String toString() { .append("language=").append(language).append(",") .append("version=").append(version.getVersion()).append(",") .append("eventMeshEnv=").append(eventMeshEnv).append(",") - .append("eventMeshRegion=").append(eventMeshRegion).append(",") .append("eventMeshIdc=").append(eventMeshIdc).append(",") - .append("eventMeshDcn=").append(eventMeshDcn).append(",") .append("eventMeshCluster=").append(eventMeshCluster).append(",") .append("eventMeshIp=").append(eventMeshIp).append("}"); return sb.toString(); diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeader.java index 9571ba5d85..2f8fc63f70 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeader.java @@ -40,15 +40,9 @@ public class PushMessageResponseHeader extends Header { //请求方所在环境编号 private String env; - //请求方所在区域编码 - private String region; - //请求方所在IDC private String idc; - //请求方所在DCN - private String dcn; - //请求方的子系统 private String sys; @@ -112,14 +106,6 @@ public void setEnv(String env) { this.env = env; } - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - public String getIdc() { return idc; } @@ -128,14 +114,6 @@ public void setIdc(String idc) { this.idc = idc; } - public String getDcn() { - return dcn; - } - - public void setDcn(String dcn) { - this.dcn = dcn; - } - public String getSys() { return sys; } @@ -160,16 +138,14 @@ public void setIp(String ip) { this.ip = ip; } - public static PushMessageResponseHeader buildHeader(int requestCode, String clientEnv, String clientRegion, String clientIDC, - String clientDCN, String clientSysId, String clientPid, String clientIP) { + public static PushMessageResponseHeader buildHeader(int requestCode, String clientEnv, String clientIDC, + String clientSysId, String clientPid, String clientIP) { PushMessageResponseHeader pushMessageResponseHeader = new PushMessageResponseHeader(); pushMessageResponseHeader.setCode(requestCode); pushMessageResponseHeader.setVersion(ProtocolVersion.V1); pushMessageResponseHeader.setLanguage(Constants.LANGUAGE_JAVA); pushMessageResponseHeader.setEnv(clientEnv); - pushMessageResponseHeader.setRegion(clientRegion); pushMessageResponseHeader.setIdc(clientIDC); - pushMessageResponseHeader.setDcn(clientDCN); pushMessageResponseHeader.setSys(clientSysId); pushMessageResponseHeader.setPid(clientPid); pushMessageResponseHeader.setIp(clientIP); @@ -184,9 +160,7 @@ public String toString() { .append("language=").append(language).append(",") .append("version=").append(version).append(",") .append("env=").append(env).append(",") - .append("region=").append(region).append(",") .append("idc=").append(idc).append(",") - .append("dcn=").append(dcn).append(",") .append("sys=").append(sys).append(",") .append("pid=").append(pid).append(",") .append("ip=").append(ip).append(",") @@ -202,9 +176,7 @@ public Map toMap() { map.put(ProtocolKey.LANGUAGE, language); map.put(ProtocolKey.VERSION, version); map.put(ProtocolKey.ClientInstanceKey.ENV, env); - map.put(ProtocolKey.ClientInstanceKey.REGION, region); map.put(ProtocolKey.ClientInstanceKey.IDC, idc); - map.put(ProtocolKey.ClientInstanceKey.DCN, dcn); map.put(ProtocolKey.ClientInstanceKey.SYS, sys); map.put(ProtocolKey.ClientInstanceKey.PID, pid); map.put(ProtocolKey.ClientInstanceKey.IP, ip); diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeader.java index 3a25164787..e7d347efa0 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeader.java @@ -41,15 +41,9 @@ public class ReplyMessageRequestHeader extends Header { //请求方所在环境编号 private String env; - //请求方所在区域编码 - private String region; - //请求方所在IDC private String idc; - //请求方所在DCN - private String dcn; - //请求方的子系统 private String sys; @@ -113,14 +107,6 @@ public void setEnv(String env) { this.env = env; } - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - public String getIdc() { return idc; } @@ -129,14 +115,6 @@ public void setIdc(String idc) { this.idc = idc; } - public String getDcn() { - return dcn; - } - - public void setDcn(String dcn) { - this.dcn = dcn; - } - public String getSys() { return sys; } @@ -169,9 +147,7 @@ public static ReplyMessageRequestHeader buildHeader(Map headerPa ? Constants.LANGUAGE_JAVA : MapUtils.getString(headerParam, ProtocolKey.LANGUAGE); header.setLanguage(lan); header.setEnv(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.ENV)); - header.setRegion(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.REGION)); header.setIdc(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IDC)); - header.setDcn(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.DCN)); header.setSys(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.SYS)); header.setPid(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.PID)); header.setIp(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IP)); @@ -187,9 +163,7 @@ public Map toMap() { map.put(ProtocolKey.LANGUAGE, language); map.put(ProtocolKey.VERSION, version); map.put(ProtocolKey.ClientInstanceKey.ENV, env); - map.put(ProtocolKey.ClientInstanceKey.REGION, region); map.put(ProtocolKey.ClientInstanceKey.IDC, idc); - map.put(ProtocolKey.ClientInstanceKey.DCN, dcn); map.put(ProtocolKey.ClientInstanceKey.SYS, sys); map.put(ProtocolKey.ClientInstanceKey.PID, pid); map.put(ProtocolKey.ClientInstanceKey.IP, ip); @@ -206,9 +180,7 @@ public String toString() { .append("language=").append(language).append(",") .append("version=").append(version).append(",") .append("env=").append(env).append(",") - .append("region=").append(region).append(",") .append("idc=").append(idc).append(",") - .append("dcn=").append(dcn).append(",") .append("sys=").append(sys).append(",") .append("pid=").append(pid).append(",") .append("ip=").append(ip).append(",") diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeader.java index fb2f42f06d..33fd373251 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeader.java @@ -38,15 +38,9 @@ public class ReplyMessageResponseHeader extends Header { //处理该次Request请求的eventMesh所在的环境编号 private String eventMeshEnv; - //处理该次Request请求的eventMesh所在区域 - private String eventMeshRegion; - //处理该次Request请求的eventMesh所在IDC private String eventMeshIdc; - //处理该次Request请求的eventMesh所在DCN - private String eventMeshDcn; - public int getCode() { return code; } @@ -79,14 +73,6 @@ public void setEventMeshEnv(String eventMeshEnv) { this.eventMeshEnv = eventMeshEnv; } - public String getEventMeshRegion() { - return eventMeshRegion; - } - - public void setEventMeshRegion(String eventMeshRegion) { - this.eventMeshRegion = eventMeshRegion; - } - public String getEventMeshIdc() { return eventMeshIdc; } @@ -95,24 +81,14 @@ public void setEventMeshIdc(String eventMeshIdc) { this.eventMeshIdc = eventMeshIdc; } - public String getEventMeshDcn() { - return eventMeshDcn; - } - - public void setEventMeshDcn(String eventMeshDcn) { - this.eventMeshDcn = eventMeshDcn; - } - public static ReplyMessageResponseHeader buildHeader(Integer requestCode, String eventMeshCluster, - String eventMeshIp, String eventMeshEnv, String eventMeshRegion, - String eventMeshDcn, String eventMeshIDC) { + String eventMeshIp, String eventMeshEnv, + String eventMeshIDC) { ReplyMessageResponseHeader replyMessageResponseHeader = new ReplyMessageResponseHeader(); replyMessageResponseHeader.setCode(requestCode); replyMessageResponseHeader.setEventMeshCluster(eventMeshCluster); - replyMessageResponseHeader.setEventMeshDcn(eventMeshDcn); replyMessageResponseHeader.setEventMeshIp(eventMeshIp); replyMessageResponseHeader.setEventMeshEnv(eventMeshEnv); - replyMessageResponseHeader.setEventMeshRegion(eventMeshRegion); replyMessageResponseHeader.setEventMeshIdc(eventMeshIDC); return replyMessageResponseHeader; } @@ -123,9 +99,7 @@ public String toString() { sb.append("replyMessageResponseHeader={") .append("code=").append(code).append(",") .append("eventMeshEnv=").append(eventMeshEnv).append(",") - .append("eventMeshRegion=").append(eventMeshRegion).append(",") .append("eventMeshIdc=").append(eventMeshIdc).append(",") - .append("eventMeshDcn=").append(eventMeshDcn).append(",") .append("eventMeshCluster=").append(eventMeshCluster).append(",") .append("eventMeshIp=").append(eventMeshIp).append("}"); return sb.toString(); @@ -139,8 +113,6 @@ public Map toMap() { map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, eventMeshIp); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, eventMeshEnv); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, eventMeshIdc); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHREGION, eventMeshRegion); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHDCN, eventMeshDcn); return map; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchRequestHeader.java index fd62ccefcd..f981ceb2bf 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchRequestHeader.java @@ -42,15 +42,9 @@ public class SendMessageBatchRequestHeader extends Header { //请求方所在环境编号 private String env; - //请求方所在区域编码 - private String region; - //请求方所在IDC private String idc; - //请求方所在DCN - private String dcn; - //请求方的子系统 private String sys; @@ -114,14 +108,6 @@ public void setEnv(String env) { this.env = env; } - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - public String getIdc() { return idc; } @@ -130,14 +116,6 @@ public void setIdc(String idc) { this.idc = idc; } - public String getDcn() { - return dcn; - } - - public void setDcn(String dcn) { - this.dcn = dcn; - } - public String getSys() { return sys; } @@ -170,9 +148,7 @@ public static SendMessageBatchRequestHeader buildHeader(final Map toMap() { map.put(ProtocolKey.LANGUAGE, language); map.put(ProtocolKey.VERSION, version); map.put(ProtocolKey.ClientInstanceKey.ENV, env); - map.put(ProtocolKey.ClientInstanceKey.REGION, region); map.put(ProtocolKey.ClientInstanceKey.IDC, idc); - map.put(ProtocolKey.ClientInstanceKey.DCN, dcn); map.put(ProtocolKey.ClientInstanceKey.SYS, sys); map.put(ProtocolKey.ClientInstanceKey.PID, pid); map.put(ProtocolKey.ClientInstanceKey.IP, ip); @@ -207,9 +181,7 @@ public String toString() { .append("language=").append(language).append(",") .append("version=").append(version).append(",") .append("env=").append(env).append(",") - .append("region=").append(region).append(",") .append("idc=").append(idc).append(",") - .append("dcn=").append(dcn).append(",") .append("sys=").append(sys).append(",") .append("pid=").append(pid).append(",") .append("ip=").append(ip).append(",") diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchResponseHeader.java index c008ed3cb1..d06660e5b5 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchResponseHeader.java @@ -38,15 +38,9 @@ public class SendMessageBatchResponseHeader extends Header { //处理该次Request请求的eventMesh所在的环境编号 private String eventMeshEnv; - //处理该次Request请求的eventMesh所在区域 - private String eventMeshRegion; - //处理该次Request请求的eventMesh所在IDC private String eventMeshIdc; - //处理该次Request请求的eventMesh所在DCN - private String eventMeshDcn; - public int getCode() { return code; } @@ -79,14 +73,6 @@ public void setEventMeshEnv(String eventMeshEnv) { this.eventMeshEnv = eventMeshEnv; } - public String getEventMeshRegion() { - return eventMeshRegion; - } - - public void setEventMeshRegion(String eventMeshRegion) { - this.eventMeshRegion = eventMeshRegion; - } - public String getEventMeshIdc() { return eventMeshIdc; } @@ -95,23 +81,13 @@ public void setEventMeshIdc(String eventMeshIdc) { this.eventMeshIdc = eventMeshIdc; } - public String getEventMeshDcn() { - return eventMeshDcn; - } - - public void setEventMeshDcn(String eventMeshDcn) { - this.eventMeshDcn = eventMeshDcn; - } - public static SendMessageBatchResponseHeader buildHeader(Integer requestCode, String eventMeshCluster, - String eventMeshIp, String eventMeshEnv, String eventMeshRegion, - String eventMeshDcn, String eventMeshIDC) { + String eventMeshIp, String eventMeshEnv, + String eventMeshIDC) { SendMessageBatchResponseHeader sendMessageBatchResponseHeader = new SendMessageBatchResponseHeader(); sendMessageBatchResponseHeader.setCode(requestCode); sendMessageBatchResponseHeader.setEventMeshCluster(eventMeshCluster); - sendMessageBatchResponseHeader.setEventMeshDcn(eventMeshDcn); sendMessageBatchResponseHeader.setEventMeshEnv(eventMeshEnv); - sendMessageBatchResponseHeader.setEventMeshRegion(eventMeshRegion); sendMessageBatchResponseHeader.setEventMeshIdc(eventMeshIDC); sendMessageBatchResponseHeader.setEventMeshIp(eventMeshIp); return sendMessageBatchResponseHeader; @@ -123,9 +99,7 @@ public String toString() { sb.append("sendMessageBatchResponseHeader={") .append("code=").append(code).append(",") .append("eventMeshEnv=").append(eventMeshEnv).append(",") - .append("eventMeshRegion=").append(eventMeshRegion).append(",") .append("eventMeshIdc=").append(eventMeshIdc).append(",") - .append("eventMeshDcn=").append(eventMeshDcn).append(",") .append("eventMeshCluster=").append(eventMeshCluster).append(",") .append("eventMeshIp=").append(eventMeshIp).append("}"); return sb.toString(); @@ -138,9 +112,7 @@ public Map toMap() { map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER, eventMeshCluster); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, eventMeshIp); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, eventMeshEnv); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHREGION, eventMeshRegion); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, eventMeshIdc); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHDCN, eventMeshDcn); return map; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2RequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2RequestHeader.java index 8722d68a0d..1e7468e45d 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2RequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2RequestHeader.java @@ -41,15 +41,9 @@ public class SendMessageBatchV2RequestHeader extends Header { //请求方所在环境编号 private String env; - //请求方所在区域编码 - private String region; - //请求方所在IDC private String idc; - //请求方所在DCN - private String dcn; - //请求方的子系统 private String sys; @@ -113,14 +107,6 @@ public void setEnv(String env) { this.env = env; } - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - public String getIdc() { return idc; } @@ -129,14 +115,6 @@ public void setIdc(String idc) { this.idc = idc; } - public String getDcn() { - return dcn; - } - - public void setDcn(String dcn) { - this.dcn = dcn; - } - public String getSys() { return sys; } @@ -169,9 +147,7 @@ public static SendMessageBatchV2RequestHeader buildHeader(final Map toMap() { map.put(ProtocolKey.LANGUAGE, language); map.put(ProtocolKey.VERSION, version); map.put(ProtocolKey.ClientInstanceKey.ENV, env); - map.put(ProtocolKey.ClientInstanceKey.REGION, region); map.put(ProtocolKey.ClientInstanceKey.IDC, idc); - map.put(ProtocolKey.ClientInstanceKey.DCN, dcn); map.put(ProtocolKey.ClientInstanceKey.SYS, sys); map.put(ProtocolKey.ClientInstanceKey.PID, pid); map.put(ProtocolKey.ClientInstanceKey.IP, ip); @@ -206,9 +180,7 @@ public String toString() { .append("language=").append(language).append(",") .append("version=").append(version).append(",") .append("env=").append(env).append(",") - .append("region=").append(region).append(",") .append("idc=").append(idc).append(",") - .append("dcn=").append(dcn).append(",") .append("sys=").append(sys).append(",") .append("pid=").append(pid).append(",") .append("ip=").append(ip).append(",") diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2ResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2ResponseHeader.java index c284fc0d59..1544381b04 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2ResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2ResponseHeader.java @@ -37,15 +37,9 @@ public class SendMessageBatchV2ResponseHeader extends Header { //处理该次Request请求的eventMesh所在的环境编号 private String eventMeshEnv; - //处理该次Request请求的eventMesh所在区域 - private String eventMeshRegion; - //处理该次Request请求的eventMesh所在IDC private String eventMeshIdc; - //处理该次Request请求的eventMesh所在DCN - private String eventMeshDcn; - public int getCode() { return code; } @@ -78,14 +72,6 @@ public void setEventMeshEnv(String eventMeshEnv) { this.eventMeshEnv = eventMeshEnv; } - public String getEventMeshRegion() { - return eventMeshRegion; - } - - public void setEventMeshRegion(String eventMeshRegion) { - this.eventMeshRegion = eventMeshRegion; - } - public String getEventMeshIdc() { return eventMeshIdc; } @@ -94,23 +80,13 @@ public void setEventMeshIdc(String eventMeshIdc) { this.eventMeshIdc = eventMeshIdc; } - public String getEventMeshDcn() { - return eventMeshDcn; - } - - public void setEventMeshDcn(String eventMeshDcn) { - this.eventMeshDcn = eventMeshDcn; - } - public static SendMessageBatchV2ResponseHeader buildHeader(Integer requestCode, String eventMeshCluster, - String eventMeshIp, String eventMeshEnv, String eventMeshRegion, - String eventMeshDcn, String eventMeshIDC) { + String eventMeshIp, String eventMeshEnv, + String eventMeshIDC) { SendMessageBatchV2ResponseHeader header = new SendMessageBatchV2ResponseHeader(); header.setCode(requestCode); header.setEventMeshCluster(eventMeshCluster); - header.setEventMeshDcn(eventMeshDcn); header.setEventMeshEnv(eventMeshEnv); - header.setEventMeshRegion(eventMeshRegion); header.setEventMeshIdc(eventMeshIDC); header.setEventMeshIp(eventMeshIp); return header; @@ -122,9 +98,7 @@ public String toString() { sb.append("sendMessageBatchV2ResponseHeader={") .append("code=").append(code).append(",") .append("eventMeshEnv=").append(eventMeshEnv).append(",") - .append("eventMeshRegion=").append(eventMeshRegion).append(",") .append("eventMeshIdc=").append(eventMeshIdc).append(",") - .append("eventMeshDcn=").append(eventMeshDcn).append(",") .append("eventMeshCluster=").append(eventMeshCluster).append(",") .append("eventMeshIp=").append(eventMeshIp).append("}"); return sb.toString(); @@ -137,9 +111,7 @@ public Map toMap() { map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER, eventMeshCluster); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, eventMeshIp); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, eventMeshEnv); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHREGION, eventMeshRegion); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, eventMeshIdc); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHDCN, eventMeshDcn); return map; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageRequestHeader.java index 3a1778f7ff..8512529baa 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageRequestHeader.java @@ -41,15 +41,9 @@ public class SendMessageRequestHeader extends Header { //请求方所在环境编号 private String env; - //请求方所在区域编码 - private String region; - //请求方所在IDC private String idc; - //请求方所在DCN - private String dcn; - //请求方的子系统 private String sys; @@ -113,14 +107,6 @@ public void setEnv(String env) { this.env = env; } - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - public String getIdc() { return idc; } @@ -129,14 +115,6 @@ public void setIdc(String idc) { this.idc = idc; } - public String getDcn() { - return dcn; - } - - public void setDcn(String dcn) { - this.dcn = dcn; - } - public String getSys() { return sys; } @@ -169,9 +147,7 @@ public static SendMessageRequestHeader buildHeader(Map headerPar ? Constants.LANGUAGE_JAVA : MapUtils.getString(headerParam, ProtocolKey.LANGUAGE); header.setLanguage(lan); header.setEnv(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.ENV)); - header.setRegion(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.REGION)); header.setIdc(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IDC)); - header.setDcn(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.DCN)); header.setSys(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.SYS)); header.setPid(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.PID)); header.setIp(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IP)); @@ -187,9 +163,7 @@ public Map toMap() { map.put(ProtocolKey.LANGUAGE, language); map.put(ProtocolKey.VERSION, version); map.put(ProtocolKey.ClientInstanceKey.ENV, env); - map.put(ProtocolKey.ClientInstanceKey.REGION, region); map.put(ProtocolKey.ClientInstanceKey.IDC, idc); - map.put(ProtocolKey.ClientInstanceKey.DCN, dcn); map.put(ProtocolKey.ClientInstanceKey.SYS, sys); map.put(ProtocolKey.ClientInstanceKey.PID, pid); map.put(ProtocolKey.ClientInstanceKey.IP, ip); @@ -206,9 +180,7 @@ public String toString() { .append("language=").append(language).append(",") .append("version=").append(version).append(",") .append("env=").append(env).append(",") - .append("region=").append(region).append(",") .append("idc=").append(idc).append(",") - .append("dcn=").append(dcn).append(",") .append("sys=").append(sys).append(",") .append("pid=").append(pid).append(",") .append("ip=").append(ip).append(",") diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageResponseHeader.java index 2f14bd6749..caa5eed8ad 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageResponseHeader.java @@ -38,15 +38,9 @@ public class SendMessageResponseHeader extends Header { //处理该次Request请求的eventMesh所在的环境编号 private String eventMeshEnv; - //处理该次Request请求的eventMesh所在区域 - private String eventMeshRegion; - //处理该次Request请求的eventMesh所在IDC private String eventMeshIdc; - //处理该次Request请求的eventMesh所在DCN - private String eventMeshDcn; - public int getCode() { return code; } @@ -79,14 +73,6 @@ public void setEventMeshEnv(String eventMeshEnv) { this.eventMeshEnv = eventMeshEnv; } - public String getEventMeshRegion() { - return eventMeshRegion; - } - - public void setEventMeshRegion(String eventMeshRegion) { - this.eventMeshRegion = eventMeshRegion; - } - public String getEventMeshIdc() { return eventMeshIdc; } @@ -95,24 +81,14 @@ public void setEventMeshIdc(String eventMeshIdc) { this.eventMeshIdc = eventMeshIdc; } - public String getEventMeshDcn() { - return eventMeshDcn; - } - - public void setEventMeshDcn(String eventMeshDcn) { - this.eventMeshDcn = eventMeshDcn; - } - public static SendMessageResponseHeader buildHeader(Integer requestCode, String eventMeshCluster, - String eventMeshIp, String eventMeshEnv, String eventMeshRegion, - String eventMeshDcn, String eventMeshIDC) { + String eventMeshIp, String eventMeshEnv, + String eventMeshIDC) { SendMessageResponseHeader sendMessageResponseHeader = new SendMessageResponseHeader(); sendMessageResponseHeader.setCode(requestCode); sendMessageResponseHeader.setEventMeshCluster(eventMeshCluster); - sendMessageResponseHeader.setEventMeshDcn(eventMeshDcn); sendMessageResponseHeader.setEventMeshIp(eventMeshIp); sendMessageResponseHeader.setEventMeshEnv(eventMeshEnv); - sendMessageResponseHeader.setEventMeshRegion(eventMeshRegion); sendMessageResponseHeader.setEventMeshIdc(eventMeshIDC); return sendMessageResponseHeader; } @@ -123,9 +99,7 @@ public String toString() { sb.append("sendMessageResponseHeader={") .append("code=").append(code).append(",") .append("eventMeshEnv=").append(eventMeshEnv).append(",") - .append("eventMeshRegion=").append(eventMeshRegion).append(",") .append("eventMeshIdc=").append(eventMeshIdc).append(",") - .append("eventMeshDcn=").append(eventMeshDcn).append(",") .append("eventMeshCluster=").append(eventMeshCluster).append(",") .append("eventMeshIp=").append(eventMeshIp).append("}"); return sb.toString(); @@ -138,9 +112,7 @@ public Map toMap() { map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER, eventMeshCluster); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, eventMeshIp); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, eventMeshEnv); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHREGION, eventMeshRegion); map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, eventMeshIdc); - map.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHDCN, eventMeshDcn); return map; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Subscription.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Subscription.java index 83b0dc9fcc..3fb74b95b0 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Subscription.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Subscription.java @@ -17,25 +17,27 @@ package org.apache.eventmesh.common.protocol.tcp; +import org.apache.eventmesh.common.protocol.SubscriptionItem; + import java.util.LinkedList; import java.util.List; public class Subscription { - private List topicList = new LinkedList<>(); + private List topicList = new LinkedList<>(); public Subscription() { } - public Subscription(List topicList) { + public Subscription(List topicList) { this.topicList = topicList; } - public List getTopicList() { + public List getTopicList() { return topicList; } - public void setTopicList(List topicList) { + public void setTopicList(List topicList) { this.topicList = topicList; } @@ -45,6 +47,4 @@ public String toString() { "topicList=" + topicList + '}'; } - - } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/UserAgent.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/UserAgent.java index 27ba693929..14b5058e69 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/UserAgent.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/UserAgent.java @@ -21,7 +21,6 @@ public class UserAgent { private String env; private String subsystem; - private String dcn; private String path; private int pid; private String host; @@ -30,12 +29,30 @@ public class UserAgent { private String username; private String password; private String idc; + private String producerGroup; + private String consumerGroup; private String purpose; private int unack = 0; public UserAgent() { } + public String getProducerGroup() { + return producerGroup; + } + + public void setProducerGroup(String producerGroup) { + this.producerGroup = producerGroup; + } + + public String getConsumerGroup() { + return consumerGroup; + } + + public void setConsumerGroup(String consumerGroup) { + this.consumerGroup = consumerGroup; + } + public String getEnv() { return env; } @@ -60,14 +77,6 @@ public void setSubsystem(String subsystem) { this.subsystem = subsystem; } - public String getDcn() { - return dcn; - } - - public void setDcn(String dcn) { - this.dcn = dcn; - } - public String getPath() { return path; } @@ -145,7 +154,6 @@ public String toString() { return "UserAgent{" + "env='" + env + '\'' + "subsystem='" + subsystem + '\'' + - ", dcn='" + dcn + '\'' + ", path='" + path + '\'' + ", pid=" + pid + ", host='" + host + '\'' + @@ -168,7 +176,6 @@ public boolean equals(Object o) { if (port != userAgent.port) return false; if (unack != userAgent.unack) return false; if (subsystem != null ? !subsystem.equals(userAgent.subsystem) : userAgent.subsystem != null) return false; - if (dcn != null ? !dcn.equals(userAgent.dcn) : userAgent.dcn != null) return false; if (path != null ? !path.equals(userAgent.path) : userAgent.path != null) return false; if (host != null ? !host.equals(userAgent.host) : userAgent.host != null) return false; if (purpose != null ? !purpose.equals(userAgent.purpose) : userAgent.purpose != null) return false; @@ -182,7 +189,6 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = subsystem != null ? subsystem.hashCode() : 0; - result = 31 * result + (dcn != null ? dcn.hashCode() : 0); result = 31 * result + (path != null ? path.hashCode() : 0); result = 31 * result + pid; result = 31 * result + (host != null ? host.hashCode() : 0); diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelectorTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelectorTest.java new file mode 100644 index 0000000000..4f7198f899 --- /dev/null +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelectorTest.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.common.loadbalance; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class RandomLoadBalanceSelectorTest { + + private RandomLoadBalanceSelector randomLoadBalanceSelector; + + private Logger logger = LoggerFactory.getLogger(RandomLoadBalanceSelectorTest.class); + + @Before + public void befor() { + List address = new ArrayList<>(); + address.add("A"); + address.add("B"); + address.add("C"); + randomLoadBalanceSelector = new RandomLoadBalanceSelector<>(address); + } + + + @Test + public void testSelect() { + Map addressToNum = new HashMap<>(); + for (int i = 0; i < 100; i++) { + String select = randomLoadBalanceSelector.select(); + addressToNum.put(select, addressToNum.getOrDefault(select, 0) + 1); + } + addressToNum.forEach((key, value) -> logger.info("{} : {}", key, value)); + // just assert success if no exception + Assert.assertTrue(true); + } + + @Test + public void testGetType() { + Assert.assertEquals(LoadBalanceType.RANDOM, randomLoadBalanceSelector.getType()); + } +} \ No newline at end of file diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelectorTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelectorTest.java new file mode 100644 index 0000000000..d37aed367b --- /dev/null +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelectorTest.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.common.loadbalance; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class WeightRoundRobinLoadBalanceSelectorTest { + + private Logger logger = LoggerFactory.getLogger(WeightRoundRobinLoadBalanceSelectorTest.class); + + private WeightRoundRobinLoadBalanceSelector weightRoundRobinLoadBalanceSelector; + + @Before + public void before() { + List> weightList = new ArrayList<>(); + weightList.add(new Weight<>("A", 10)); + weightList.add(new Weight<>("B", 20)); + weightList.add(new Weight<>("C", 30)); + weightRoundRobinLoadBalanceSelector = new WeightRoundRobinLoadBalanceSelector<>(weightList); + } + + @Test + public void testSelect() { + Map addressToNum = new HashMap<>(); + for (int i = 0; i < 100_000; i++) { + String select = weightRoundRobinLoadBalanceSelector.select(); + addressToNum.put(select, addressToNum.getOrDefault(select, 0) + 1); + } + addressToNum.forEach((key, value) -> { + logger.info("{}: {}", key, value); + }); + Assert.assertTrue(addressToNum.get("B") > addressToNum.get("A")); + Assert.assertTrue(addressToNum.get("C") > addressToNum.get("B")); + } + + @Test + public void testGetType() { + Assert.assertEquals(LoadBalanceType.WEIGHT_ROUND_ROBIN, weightRoundRobinLoadBalanceSelector.getType()); + } +} \ No newline at end of file diff --git a/eventmesh-connector-api/gradle.properties b/eventmesh-connector-api/gradle.properties index 9d1744e07a..c06c465567 100644 --- a/eventmesh-connector-api/gradle.properties +++ b/eventmesh-connector-api/gradle.properties @@ -15,7 +15,7 @@ # limitations under the License. # group=org.apache.eventmesh -version=1.2.0-SNAPSHOT +version=1.2.0-release jdk=1.8 mavenUserName= mavenPassword= \ No newline at end of file diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/event/ConsumerGroupInstanceChangeEvent.java b/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/EventMeshAction.java similarity index 87% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/event/ConsumerGroupInstanceChangeEvent.java rename to eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/EventMeshAction.java index f06ba0263a..4fda6d05b6 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/event/ConsumerGroupInstanceChangeEvent.java +++ b/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/EventMeshAction.java @@ -14,8 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package org.apache.eventmesh.api; -package org.apache.eventmesh.runtime.core.consumergroup.event; +public enum EventMeshAction { + CommitMessage, -public class ConsumerGroupInstanceChangeEvent { + ReconsumeLater, + + ManualAck } diff --git a/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/EventMeshAsyncConsumeContext.java b/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/EventMeshAsyncConsumeContext.java new file mode 100644 index 0000000000..c7e4e7fb73 --- /dev/null +++ b/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/EventMeshAsyncConsumeContext.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.eventmesh.api; + +import io.openmessaging.api.Action; +import io.openmessaging.api.AsyncConsumeContext; + +public abstract class EventMeshAsyncConsumeContext extends AsyncConsumeContext { + + private AbstractContext abstractContext; + + public AbstractContext getAbstractContext() { + return abstractContext; + } + + public void setAbstractContext(AbstractContext abstractContext) { + this.abstractContext = abstractContext; + } + + public abstract void commit(EventMeshAction action); + + @Override + public void commit(Action action) { + throw new UnsupportedOperationException("not support yet"); + } +} \ No newline at end of file diff --git a/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/consumer/MeshMQPushConsumer.java b/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/consumer/MeshMQPushConsumer.java index b495169d20..5e60e0e0df 100644 --- a/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/consumer/MeshMQPushConsumer.java +++ b/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/consumer/MeshMQPushConsumer.java @@ -30,11 +30,6 @@ public interface MeshMQPushConsumer extends Consumer { void init(Properties keyValue) throws Exception; - @Override - void start(); - -// void updateOffset(List msgs, ConsumeConcurrentlyContext context); - void updateOffset(List msgs, AbstractContext context); // void registerMessageListener(MessageListenerConcurrently messageListenerConcurrently); @@ -43,6 +38,4 @@ public interface MeshMQPushConsumer extends Consumer { @Override void unsubscribe(String topic); - - AbstractContext getContext(); } diff --git a/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/producer/MeshMQProducer.java b/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/producer/MeshMQProducer.java index 929654fb30..82ca583ce7 100644 --- a/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/producer/MeshMQProducer.java +++ b/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/producer/MeshMQProducer.java @@ -29,9 +29,6 @@ public interface MeshMQProducer extends Producer { void init(Properties properties) throws Exception; - @Override - void start(); - void send(Message message, SendCallback sendCallback) throws Exception; void request(Message message, SendCallback sendCallback, RRCallback rrCallback, long timeout) throws Exception; @@ -40,12 +37,8 @@ public interface MeshMQProducer extends Producer { boolean reply(final Message message, final SendCallback sendCallback) throws Exception; - MeshMQProducer getMeshMQProducer(); - - String buildMQClientId(); + void checkTopicExist(String topic) throws Exception; void setExtFields(); - void getDefaultTopicRouteInfoFromNameServer(String topic, long timeout) throws Exception; - } diff --git a/eventmesh-connector-rocketmq/gradle.properties b/eventmesh-connector-rocketmq/gradle.properties index 9b89108e79..383fbc021b 100644 --- a/eventmesh-connector-rocketmq/gradle.properties +++ b/eventmesh-connector-rocketmq/gradle.properties @@ -14,7 +14,7 @@ # limitations under the License. group=org.apache.eventmesh -version=1.2.0 +version=1.2.0-release rocketmq_version=4.7.1 mavenUserName= mavenPassword= \ No newline at end of file diff --git a/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/common/Constants.java b/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/common/Constants.java index 9d54a2ebef..fc55a68739 100644 --- a/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/common/Constants.java +++ b/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/common/Constants.java @@ -18,11 +18,8 @@ package org.apache.eventmesh.connector.rocketmq.common; public class Constants { - public static final String BROADCAST_PREFIX = "broadcast-"; - - public final static String CONSUMER_GROUP_NAME_PREFIX = "ConsumerGroup-"; - public final static String PRODUCER_GROUP_NAME_PREFIX = "ProducerGroup-"; + public static final String BROADCAST_PREFIX = "broadcast-"; public static final String PROPERTY_MESSAGE_TIMEOUT = "TIMEOUT"; diff --git a/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/common/EventMeshConstants.java b/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/common/EventMeshConstants.java index cce1645ec1..69fb8c10dc 100644 --- a/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/common/EventMeshConstants.java +++ b/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/common/EventMeshConstants.java @@ -29,10 +29,6 @@ public class EventMeshConstants { public static final String BROADCAST_PREFIX = "broadcast-"; - public final static String CONSUMER_GROUP_NAME_PREFIX = "ConsumerGroup-"; - - public final static String PRODUCER_GROUP_NAME_PREFIX = "ProducerGroup-"; - public static final String DEFAULT_CHARSET = "UTF-8"; public static final String EVENTMESH_CONF_HOME = System.getProperty("confPath", System.getenv("confPath")); @@ -85,7 +81,6 @@ public class EventMeshConstants { public static final String TAG = "TAG"; - public static final String MANAGE_DCN = "dcn"; public static final String MANAGE_SUBSYSTEM = "subSystem"; public static final String MANAGE_IP = "ip"; public static final String MANAGE_PORT = "port"; diff --git a/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/PushConsumerImpl.java b/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/PushConsumerImpl.java index 2193ca1574..47565e3b03 100644 --- a/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/PushConsumerImpl.java +++ b/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/PushConsumerImpl.java @@ -21,9 +21,6 @@ import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; - -import io.openmessaging.api.Action; -import io.openmessaging.api.AsyncConsumeContext; import io.openmessaging.api.AsyncGenericMessageListener; import io.openmessaging.api.AsyncMessageListener; import io.openmessaging.api.Consumer; @@ -32,8 +29,8 @@ import io.openmessaging.api.MessageListener; import io.openmessaging.api.MessageSelector; import io.openmessaging.api.exception.OMSRuntimeException; - -import org.apache.eventmesh.api.AbstractContext; +import org.apache.eventmesh.api.EventMeshAction; +import org.apache.eventmesh.api.EventMeshAsyncConsumeContext; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.connector.rocketmq.common.EventMeshConstants; import org.apache.eventmesh.connector.rocketmq.config.ClientConfig; @@ -55,7 +52,6 @@ public class PushConsumerImpl implements Consumer { private AtomicBoolean started = new AtomicBoolean(false); private final Map subscribeTable = new ConcurrentHashMap<>(); private final ClientConfig clientConfig; - private EventMeshConsumeConcurrentlyContext context; public PushConsumerImpl(final Properties properties) { this.rocketmqPushConsumer = new DefaultMQPushConsumer(); @@ -93,7 +89,6 @@ public PushConsumerImpl(final Properties properties) { @Override public EventMeshConsumeConcurrentlyStatus handleMessage(MessageExt msg, EventMeshConsumeConcurrentlyContext context) { - PushConsumerImpl.this.setContext(context); if (msg == null) { return EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS; } @@ -117,12 +112,25 @@ public EventMeshConsumeConcurrentlyStatus handleMessage(MessageExt msg, EventMes final Properties contextProperties = new Properties(); contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.RECONSUME_LATER.name()); - AsyncConsumeContext omsContext = new AsyncConsumeContext() { + EventMeshAsyncConsumeContext omsContext = new EventMeshAsyncConsumeContext() { @Override - public void commit(Action action) { - contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); + public void commit(EventMeshAction action) { + switch (action){ + case CommitMessage: + contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); + break; + case ReconsumeLater: + contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.RECONSUME_LATER.name()); + break; + case ManualAck: + contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); + break; + default: + break; + } } }; + omsContext.setAbstractContext(context); listener.consume(omsMsg, omsContext); return EventMeshConsumeConcurrentlyStatus.valueOf(contextProperties.getProperty(NonStandardKeys.MESSAGE_CONSUME_STATUS)); @@ -133,7 +141,6 @@ public void commit(Action action) { @Override public EventMeshConsumeConcurrentlyStatus handleMessage(MessageExt msg, EventMeshConsumeConcurrentlyContext context) { - PushConsumerImpl.this.setContext(context); if (msg == null) { return EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS; } @@ -157,13 +164,25 @@ public EventMeshConsumeConcurrentlyStatus handleMessage(MessageExt msg, EventMes contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.RECONSUME_LATER.name()); - AsyncConsumeContext omsContext = new AsyncConsumeContext() { + EventMeshAsyncConsumeContext omsContext = new EventMeshAsyncConsumeContext() { @Override - public void commit(Action action) { - contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, - EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); + public void commit(EventMeshAction action) { + switch (action) { + case CommitMessage: + contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); + break; + case ReconsumeLater: + contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.RECONSUME_LATER.name()); + break; + case ManualAck: + contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); + break; + default: + break; + } } }; + omsContext.setAbstractContext(context); listener.consume(omsMsg, omsContext); return EventMeshConsumeConcurrentlyStatus.valueOf(contextProperties.getProperty(NonStandardKeys.MESSAGE_CONSUME_STATUS)); @@ -254,14 +273,6 @@ public DefaultMQPushConsumer getRocketmqPushConsumer() { // } // } - public AbstractContext getContext() { - return this.context; - } - - public void setContext(EventMeshConsumeConcurrentlyContext context) { - this.context = context; - } - @Override public void subscribe(String topic, String subExpression, MessageListener listener) { diff --git a/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/RocketMQConsumerImpl.java b/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/RocketMQConsumerImpl.java index ce076f8003..853c394bef 100644 --- a/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/RocketMQConsumerImpl.java +++ b/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/RocketMQConsumerImpl.java @@ -71,9 +71,7 @@ public synchronized void init(Properties keyValue) throws Exception { if (isBroadcast) { - consumerGroup = Constants.CONSUMER_GROUP_NAME_PREFIX + Constants.BROADCAST_PREFIX + consumerGroup; - } else { - consumerGroup = Constants.CONSUMER_GROUP_NAME_PREFIX + consumerGroup; + consumerGroup = Constants.BROADCAST_PREFIX + consumerGroup; } String omsNamesrv = clientConfiguration.namesrvAddr; @@ -98,12 +96,6 @@ public void subscribe(String topic, AsyncMessageListener listener) throws Except pushConsumer.subscribe(topic, "*", listener); } - @Override - public AbstractContext getContext() { - return pushConsumer.getContext(); - } - - @Override public boolean isStarted() { return pushConsumer.isStarted(); diff --git a/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/RocketMQProducerImpl.java b/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/RocketMQProducerImpl.java index 6364650035..72e20938b9 100644 --- a/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/RocketMQProducerImpl.java +++ b/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/RocketMQProducerImpl.java @@ -87,7 +87,6 @@ public void start() { producer.start(); } - @Override public synchronized void shutdown() { producer.shutdown(); @@ -115,13 +114,8 @@ public boolean reply(final Message message, final SendCallback sendCallback) thr } @Override - public MeshMQProducer getMeshMQProducer() { - return this; - } - - @Override - public String buildMQClientId() { - return producer.getRocketmqProducer().buildMQClientId(); + public void checkTopicExist(String topic) throws Exception { + this.producer.getRocketmqProducer().getDefaultMQProducerImpl().getmQClientFactory().getMQClientAPIImpl().getDefaultTopicRouteInfoFromNameServer(topic, EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); } @Override @@ -129,13 +123,6 @@ public void setExtFields() { producer.setExtFields(); } - @Override - public void getDefaultTopicRouteInfoFromNameServer(String topic, long timeout) throws Exception { - producer.getRocketmqProducer().getDefaultMQProducerImpl() - .getmQClientFactory().getMQClientAPIImpl().getDefaultTopicRouteInfoFromNameServer(topic, - timeout); - } - @Override public SendResult send(Message message) { return producer.send(message); diff --git a/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/consumer/PushConsumerImplTest.java b/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/consumer/PushConsumerImplTest.java index 186ef4a529..114053520e 100644 --- a/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/consumer/PushConsumerImplTest.java +++ b/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/consumer/PushConsumerImplTest.java @@ -32,6 +32,8 @@ import io.openmessaging.api.OMS; import io.openmessaging.api.OMSBuiltinKeys; +import org.apache.eventmesh.api.EventMeshAction; +import org.apache.eventmesh.api.EventMeshAsyncConsumeContext; import org.apache.eventmesh.connector.rocketmq.consumer.PushConsumerImpl; import org.apache.eventmesh.connector.rocketmq.domain.NonStandardKeys; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; @@ -95,7 +97,7 @@ public void testConsumeMessage() { public void consume(Message message, AsyncConsumeContext context) { assertThat(message.getSystemProperties("MESSAGE_ID")).isEqualTo("NewMsgId"); assertThat(message.getBody()).isEqualTo(testBody); - context.commit(Action.CommitMessage); + ((EventMeshAsyncConsumeContext)context).commit(EventMeshAction.CommitMessage); } }); ((MessageListenerConcurrently) rocketmqPushConsumer diff --git a/eventmesh-connector-rocketmq/src/test/resources/META-INF/services/org.apache.io.openmessaging.MessagingAccessPoint b/eventmesh-connector-rocketmq/src/test/resources/META-INF/services/org.apache.io.openmessaging.MessagingAccessPoint index 7347e69999..e326c919c7 100644 --- a/eventmesh-connector-rocketmq/src/test/resources/META-INF/services/org.apache.io.openmessaging.MessagingAccessPoint +++ b/eventmesh-connector-rocketmq/src/test/resources/META-INF/services/org.apache.io.openmessaging.MessagingAccessPoint @@ -1 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + org.apache.eventmesh.connector.rocketmq.MessagingAccessPointImpl \ No newline at end of file diff --git a/eventmesh-connector-rocketmq/src/test/resources/META-INF/services/org.apache.io.openmessaging.producer.Producer b/eventmesh-connector-rocketmq/src/test/resources/META-INF/services/org.apache.io.openmessaging.producer.Producer index 5ea8a1853f..bf0a8ddc29 100644 --- a/eventmesh-connector-rocketmq/src/test/resources/META-INF/services/org.apache.io.openmessaging.producer.Producer +++ b/eventmesh-connector-rocketmq/src/test/resources/META-INF/services/org.apache.io.openmessaging.producer.Producer @@ -1 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + org.apache.eventmesh.connector.rocketmq.producer.ProducerImpl \ No newline at end of file diff --git a/eventmesh-runtime/conf/eventmesh.properties b/eventmesh-runtime/conf/eventmesh.properties index 21b9bb76e7..035b950fc6 100644 --- a/eventmesh-runtime/conf/eventmesh.properties +++ b/eventmesh-runtime/conf/eventmesh.properties @@ -17,10 +17,8 @@ ###############################EVNETMESH-runtime ENV################################# eventMesh.server.idc=DEFAULT eventMesh.server.env=PRD -eventMesh.server.region=region1 eventMesh.server.cluster=COMMON eventMesh.server.name=EVENTMESH-runtime -eventMesh.server.dcn=010 eventMesh.sysid=0000 eventMesh.server.http.port=10105 ########################## eventMesh tcp configuration ############################ @@ -39,7 +37,7 @@ eventMesh.server.session.expiredInMills=60000 # flow control, include the global level and session level eventMesh.server.tcp.msgReqnumPerSecond=15000 eventMesh.server.session.upstreamBufferSize=20 -eventMesh.server.session.downstreamUnackSize=100 + # thread number about global scheduler eventMesh.server.global.scheduler=5 eventMesh.server.tcp.taskHandleExecutorPoolSize=8 diff --git a/eventmesh-runtime/scripts/client_manage.sh b/eventmesh-runtime/scripts/client_manage.sh index f9367a0f33..0913cc58ec 100644 --- a/eventmesh-runtime/scripts/client_manage.sh +++ b/eventmesh-runtime/scripts/client_manage.sh @@ -17,8 +17,8 @@ # specific language governing permissions and limitations # under the License. i_eg="sh client_manage.sh -i 10.255.34.160 24591" -s_eg="sh client_manage.sh -s FT0 5319" -r_eg="sh client_manage.sh -r FT0 9876 10.255.1.143 10000" +s_eg="sh client_manage.sh -s 5319" +r_eg="sh client_manage.sh -r 9876 10.255.1.143 10000" a_eg="sh client_manage.sh -a" x_eg="sh client_manage.sh -x 10.255.34.160 24591 10.255.1.143 10000" y_eg="sh client_manage.sh -y bq-bypass 10.255.1.143 10000" @@ -27,8 +27,8 @@ function printEg() { echo "param error." echo "reject client by ip_port, eg : ${i_eg}" echo "reject all clients, eg : ${a_eg}" - echo "reject clients by dcn_systemid, eg : ${s_eg}" - echo "redirect client by dcn_systemid, eg : ${r_eg}" + echo "reject clients by systemid, eg : ${s_eg}" + echo "redirect client by systemid, eg : ${r_eg}" echo "redirect client by ip port, eg : ${x_eg}" echo "redirect client by path, eg : ${y_eg}" } @@ -52,9 +52,8 @@ do CLIENT_PORT=$5 msg=`curl "http://${ADDR}/clientManage/rejectClientByIpPort?ip=${CLIENT_IP}&port=${CLIENT_PORT}"`;echo ${msg};break;; -s|--subsystem) - DCN=$4 - SUB_SYSTEM=$5 - msg=`curl "http://${ADDR}/clientManage/rejectClientBySubSystem?dcn=${DCN}&subSystem=${SUB_SYSTEM}"`;echo ${msg};break;; + SUB_SYSTEM=$4 + msg=`curl "http://${ADDR}/clientManage/rejectClientBySubSystem?subSystem=${SUB_SYSTEM}"`;echo ${msg};break;; -x|--redirectbyip) CLIENT_IP=$4 CLIENT_PORT=$5 @@ -67,11 +66,10 @@ do DEST_PROXY_PORT=$6 msg=`curl "http://${ADDR}/clientManage/redirectClientByPath?path=${CLIENT_PATH}&destProxyIp=${DEST_PROXY_IP}&destProxyPort=${DEST_PROXY_PORT}"`;echo ${msg};break;; -r|--redirect) - DCN=$4 - SUB_SYSTEM=$5 - DEST_PROXY_IP=$6 - DEST_PROXY_PORT=$7 - msg=`curl "http://${ADDR}/clientManage/redirectClientBySubSystem?dcn=${DCN}&subSystem=${SUB_SYSTEM}&destProxyIp=${DEST_PROXY_IP}&destProxyPort=${DEST_PROXY_PORT}"`;echo ${msg};break;; + SUB_SYSTEM=$4 + DEST_PROXY_IP=$5 + DEST_PROXY_PORT=$6 + msg=`curl "http://${ADDR}/clientManage/redirectClientBySubSystem?subSystem=${SUB_SYSTEM}&destProxyIp=${DEST_PROXY_IP}&destProxyPort=${DEST_PROXY_PORT}"`;echo ${msg};break;; --) shift; break;; diff --git a/eventmesh-runtime/scripts/session.sh b/eventmesh-runtime/scripts/session.sh index 86042c0479..3540cf8546 100644 --- a/eventmesh-runtime/scripts/session.sh +++ b/eventmesh-runtime/scripts/session.sh @@ -24,7 +24,6 @@ then TOPIC=$1 curl -s "http://127.0.0.1:10106/clientManage/showListenClientByTopic?topic=${TOPIC}" else - CLIENT_DCN=$1 - CLIENT_SYSTEM=$2 - curl -s "http://127.0.0.1:10106/clientManage/showClientBySystemAndDcn?dcn=${CLIENT_DCN}&subSystem=${CLIENT_SYSTEM}" + CLIENT_SYSTEM=$1 + curl -s "http://127.0.0.1:10106/clientManage/showClientBySystem?subSystem=${CLIENT_SYSTEM}" fi diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/controller/ClientManageController.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/controller/ClientManageController.java index f93e1af006..573eb02029 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/controller/ClientManageController.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/controller/ClientManageController.java @@ -17,36 +17,21 @@ package org.apache.eventmesh.runtime.admin.controller; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.net.InetSocketAddress; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; -import org.apache.commons.lang3.StringUtils; -import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.runtime.admin.handler.RedirectClientByIpPortHandler; +import org.apache.eventmesh.runtime.admin.handler.RedirectClientByPathHandler; +import org.apache.eventmesh.runtime.admin.handler.RedirectClientBySubSystemHandler; +import org.apache.eventmesh.runtime.admin.handler.RejectAllClientHandler; +import org.apache.eventmesh.runtime.admin.handler.RejectClientByIpPortHandler; +import org.apache.eventmesh.runtime.admin.handler.RejectClientBySubSystemHandler; +import org.apache.eventmesh.runtime.admin.handler.ShowClientBySystemHandler; +import org.apache.eventmesh.runtime.admin.handler.ShowClientHandler; +import org.apache.eventmesh.runtime.admin.handler.ShowListenClientByTopicHandler; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientGroupWrapper; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,713 +48,17 @@ public ClientManageController(EventMeshTCPServer eventMeshTCPServer) { public void start() throws IOException { int port = eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerAdminPort; HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); - server.createContext("/clientManage/showClient", new ShowClientHandler()); - server.createContext("/clientManage/showClientBySystemAndDcn", new ShowClientBySystemAndDcnHandler()); - server.createContext("/clientManage/rejectAllClient", new RejectAllClientHandler()); - server.createContext("/clientManage/rejectClientByIpPort", new RejectClientByIpPortHandler()); - server.createContext("/clientManage/rejectClientBySubSystem", new RejectClientBySubSystemHandler()); - server.createContext("/clientManage/redirectClientBySubSystem", new RedirectClientBySubSystemHandler()); - server.createContext("/clientManage/redirectClientByPath", new RedirectClientByPathHandler()); - server.createContext("/clientManage/redirectClientByIpPort", new RedirectClientByIpPortHandler()); -// server.createContext("/eventMesh/msg/push", new EventMeshMsgDownStreamHandler()); - server.createContext("/clientManage/showListenClientByTopic", new ShowListenClientByTopicHandler()); + server.createContext("/clientManage/showClient", new ShowClientHandler(eventMeshTCPServer)); + server.createContext("/clientManage/showClientBySystem", new ShowClientBySystemHandler(eventMeshTCPServer)); + server.createContext("/clientManage/rejectAllClient", new RejectAllClientHandler(eventMeshTCPServer)); + server.createContext("/clientManage/rejectClientByIpPort", new RejectClientByIpPortHandler(eventMeshTCPServer)); + server.createContext("/clientManage/rejectClientBySubSystem", new RejectClientBySubSystemHandler(eventMeshTCPServer)); + server.createContext("/clientManage/redirectClientBySubSystem", new RedirectClientBySubSystemHandler(eventMeshTCPServer)); + server.createContext("/clientManage/redirectClientByPath", new RedirectClientByPathHandler(eventMeshTCPServer)); + server.createContext("/clientManage/redirectClientByIpPort", new RedirectClientByIpPortHandler(eventMeshTCPServer)); + server.createContext("/clientManage/showListenClientByTopic", new ShowListenClientByTopicHandler(eventMeshTCPServer)); server.start(); logger.info("ClientManageController start success, port:{}", port); } - - private Map parsePostParameters(HttpExchange exchange) - throws IOException { - Map parameters = new HashMap<>(); - if ("post".equalsIgnoreCase(exchange.getRequestMethod())) { - InputStreamReader isr = - new InputStreamReader(exchange.getRequestBody(), "utf-8"); - BufferedReader br = new BufferedReader(isr); - String query = br.readLine(); - parseQuery(query, parameters); - } - return parameters; - } - - @SuppressWarnings("unchecked") - private void parseQuery(String query, Map parameters) - throws UnsupportedEncodingException { - - if (query != null) { - String pairs[] = query.split("&"); - - for (String pair : pairs) { - String param[] = pair.split("="); - - String key = null; - String value = null; - if (param.length > 0) { - key = URLDecoder.decode(param[0], "UTF-8"); - } - - if (param.length > 1) { - value = URLDecoder.decode(param[1], "UTF-8"); - } - - if (parameters.containsKey(key)) { - Object obj = parameters.get(key); - if (obj instanceof List) { - List values = (List) obj; - values.add(value); - } else if (obj instanceof String) { - List values = new ArrayList(); - values.add((String) obj); - values.add(value); - parameters.put(key, values); - } - } else { - parameters.put(key, value); - } - } - } - } - - /** - * 打印本eventMesh上所有客户端信息 - * - * @return - */ - class ShowClientHandler implements HttpHandler { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - String result = ""; - OutputStream out = httpExchange.getResponseBody(); - try { - String newLine = System.getProperty("line.separator"); - logger.info("showAllClient================="); - ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); - Map dcnSystemMap = clientSessionGroupMapping.statDCNSystemInfo(); - if (!dcnSystemMap.isEmpty()) { - List> list = new ArrayList<>(); - ValueComparator vc = new ValueComparator(); - for (Map.Entry entry : dcnSystemMap.entrySet()) { - list.add(entry); - } - Collections.sort(list, vc); - for (Map.Entry entry : list) { - result += String.format("System=%s | ClientNum=%d", entry.getKey(), entry.getValue().intValue()) + - newLine; - } - } - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - } catch (Exception e) { - logger.error("ShowClientHandler fail...", e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - logger.warn("out close failed...", e); - } - } - } - - } - } - - class ValueComparator implements Comparator> { - @Override - public int compare(Map.Entry x, Map.Entry y) { - return x.getValue().intValue() - y.getValue().intValue(); - } - } - - /** - * print clientInfo by subsys and dcn - * - * @return - */ - class ShowClientBySystemAndDcnHandler implements HttpHandler { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - String result = ""; - OutputStream out = httpExchange.getResponseBody(); - try { - String queryString = httpExchange.getRequestURI().getQuery(); - Map queryStringInfo = formData2Dic(queryString); - String dcn = queryStringInfo.get(EventMeshConstants.MANAGE_DCN); - String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM); - - String newLine = System.getProperty("line.separator"); - logger.info("showClientBySubsysAndDcn,subsys:{},dcn:{}=================", subSystem, dcn); - ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); - ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); - if (!sessionMap.isEmpty()) { - for (Session session : sessionMap.values()) { - if (session.getClient().getDcn().equals(dcn) && session.getClient().getSubsystem().equals(subSystem)) { - UserAgent userAgent = session.getClient(); - result += String.format("pid=%s | ip=%s | port=%s | path=%s | purpose=%s", userAgent.getPid(), userAgent - .getHost(), userAgent.getPort(), userAgent.getPath(), userAgent.getPurpose()) + newLine; - } - } - } - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - } catch (Exception e) { - logger.error("ShowClientBySystemAndDcnHandler fail...", e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - logger.warn("out close failed...", e); - } - } - } - - } - } - - - /** - * query client subscription by topic - */ - class ShowListenClientByTopicHandler implements HttpHandler { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - String result = ""; - OutputStream out = httpExchange.getResponseBody(); - try { - String queryString = httpExchange.getRequestURI().getQuery(); - Map queryStringInfo = formData2Dic(queryString); - String topic = queryStringInfo.get(EventMeshConstants.MANAGE_TOPIC); - - String newLine = System.getProperty("line.separator"); - logger.info("showListeningClientByTopic,topic:{}=================", topic); - ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); - ConcurrentHashMap clientGroupMap = clientSessionGroupMapping.getClientGroupMap(); - if (!clientGroupMap.isEmpty()) { - for (ClientGroupWrapper cgw : clientGroupMap.values()) { - Set listenSessionSet = cgw.getTopic2sessionInGroupMapping().get(topic); - if (listenSessionSet != null && listenSessionSet.size() > 0) { - result += String.format("group:%s", cgw.getGroupName()) + newLine; - for (Session session : listenSessionSet) { - UserAgent userAgent = session.getClient(); - result += String.format("pid=%s | ip=%s | port=%s | path=%s | version=%s", userAgent.getPid(), userAgent - .getHost(), userAgent.getPort(), userAgent.getPath(), userAgent.getVersion()) + newLine; - } - } - } - } - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - } catch (Exception e) { - logger.error("ShowListenClientByTopicHandler fail...", e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - logger.warn("out close failed...", e); - } - } - } - - } - } - - - /** - * remove all clients accessed by eventMesh - * - * @return - */ - class RejectAllClientHandler implements HttpHandler { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - String result = ""; - OutputStream out = httpExchange.getResponseBody(); - try { - ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); - ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); - final List successRemoteAddrs = new ArrayList(); - try { - logger.info("rejectAllClient in admin===================="); - if (!sessionMap.isEmpty()) { - for (Map.Entry entry : sessionMap.entrySet()) { - InetSocketAddress addr = EventMeshTcp2Client.serverGoodby2Client(eventMeshTCPServer, entry.getValue(), clientSessionGroupMapping); - if (addr != null) { - successRemoteAddrs.add(addr); - } - } - } - } catch (Exception e) { - logger.error("clientManage|rejectAllClient|fail", e); - result = String.format("rejectAllClient fail! sessionMap size {%d}, had reject {%s}, errorMsg : %s", - sessionMap.size(), printClients(successRemoteAddrs), e.getMessage()); - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - return; - } - result = String.format("rejectAllClient success! sessionMap size {%d}, had reject {%s}", sessionMap.size - (), printClients(successRemoteAddrs)); - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - } catch (Exception e) { - logger.error("rejectAllClient fail...", e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - logger.warn("out close failed...", e); - } - } - } - - } - } - - /** - * remove c client by ip and port - * - * @return - */ - class RejectClientByIpPortHandler implements HttpHandler { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - String result = ""; - OutputStream out = httpExchange.getResponseBody(); - try { - String queryString = httpExchange.getRequestURI().getQuery(); - Map queryStringInfo = formData2Dic(queryString); - String ip = queryStringInfo.get(EventMeshConstants.MANAGE_IP); - String port = queryStringInfo.get(EventMeshConstants.MANAGE_PORT); - - if (StringUtils.isBlank(ip) || StringUtils.isBlank(port)) { - httpExchange.sendResponseHeaders(200, 0); - result = "params illegal!"; - out.write(result.getBytes()); - return; - } - logger.info("rejectClientByIpPort in admin,ip:{},port:{}====================", ip, port); - ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); - ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); - final List successRemoteAddrs = new ArrayList(); - try { - if (!sessionMap.isEmpty()) { - for (Map.Entry entry : sessionMap.entrySet()) { - if (entry.getKey().getHostString().equals(ip) && String.valueOf(entry.getKey().getPort()).equals(port)) { - InetSocketAddress addr = EventMeshTcp2Client.serverGoodby2Client(eventMeshTCPServer, entry.getValue(), clientSessionGroupMapping); - if (addr != null) { - successRemoteAddrs.add(addr); - } - } - } - } - } catch (Exception e) { - logger.error("clientManage|rejectClientByIpPort|fail|ip={}|port={},errMsg={}", ip, port, e); - result = String.format("rejectClientByIpPort fail! {ip=%s port=%s}, had reject {%s}, errorMsg : %s", ip, - port, printClients(successRemoteAddrs), e.getMessage()); - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - return; - } - - result = String.format("rejectClientByIpPort success! {ip=%s port=%s}, had reject {%s}", ip, port, printClients - (successRemoteAddrs)); - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - } catch (Exception e) { - logger.error("rejectClientByIpPort fail...", e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - logger.warn("out close failed...", e); - } - } - } - - } - } - - - /** - * remove c client by dcn and susysId - * - * @return - */ - class RejectClientBySubSystemHandler implements HttpHandler { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - String result = ""; - OutputStream out = httpExchange.getResponseBody(); - try { - String queryString = httpExchange.getRequestURI().getQuery(); - Map queryStringInfo = formData2Dic(queryString); - String dcn = queryStringInfo.get(EventMeshConstants.MANAGE_DCN); - String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM); - - if (StringUtils.isBlank(dcn) || StringUtils.isBlank(subSystem)) { - httpExchange.sendResponseHeaders(200, 0); - result = "params illegal!"; - out.write(result.getBytes()); - return; - } - - logger.info("rejectClientBySubSystem in admin,subsys:{},dcn:{}====================", subSystem, dcn); - ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); - ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); - final List successRemoteAddrs = new ArrayList(); - try { - if (!sessionMap.isEmpty()) { - for (Session session : sessionMap.values()) { - if (session.getClient().getDcn().equals(dcn) && session.getClient().getSubsystem().equals(subSystem)) { - InetSocketAddress addr = EventMeshTcp2Client.serverGoodby2Client(eventMeshTCPServer, session, clientSessionGroupMapping); - if (addr != null) { - successRemoteAddrs.add(addr); - } - } - } - } - } catch (Exception e) { - logger.error("clientManage|rejectClientBySubSystem|fail|dcn={}|subSystemId={},errMsg={}", dcn, subSystem, e); - result = String.format("rejectClientBySubSystem fail! sessionMap size {%d}, had reject {%d} , {dcn=%s " + - "port=%s}, errorMsg : %s", sessionMap.size(), printClients(successRemoteAddrs), dcn, - subSystem, e.getMessage()); - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - return; - } - result = String.format("rejectClientBySubSystem success! sessionMap size {%d}, had reject {%s} , {dcn=%s " + - "port=%s}", sessionMap.size(), printClients(successRemoteAddrs), dcn, subSystem); - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - } catch (Exception e) { - logger.error("rejectClientBySubSystem fail...", e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - logger.warn("out close failed...", e); - } - } - } - - } - } - - /** - * redirect subsystem for subsys and dcn - * - * @return - */ - class RedirectClientBySubSystemHandler implements HttpHandler { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - String result = ""; - OutputStream out = httpExchange.getResponseBody(); - try { - String queryString = httpExchange.getRequestURI().getQuery(); - Map queryStringInfo = formData2Dic(queryString); - String dcn = queryStringInfo.get(EventMeshConstants.MANAGE_DCN); - String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM); - String destEventMeshIp = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_IP); - String destEventMeshPort = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_PORT); - - if (StringUtils.isBlank(dcn) || !StringUtils.isNumeric(subSystem) - || StringUtils.isBlank(destEventMeshIp) || StringUtils.isBlank(destEventMeshPort) - || !StringUtils.isNumeric(destEventMeshPort)) { - httpExchange.sendResponseHeaders(200, 0); - result = "params illegal!"; - out.write(result.getBytes()); - return; - } - logger.info("redirectClientBySubSystem in admin,subsys:{},dcn:{},destIp:{},destPort:{}====================", subSystem, dcn, destEventMeshIp, destEventMeshPort); - ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); - ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); - String redirectResult = ""; - try { - if (!sessionMap.isEmpty()) { - for (Session session : sessionMap.values()) { - if (session.getClient().getDcn().equals(dcn) && session.getClient().getSubsystem().equals(subSystem)) { - redirectResult += "|"; - redirectResult += EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer, destEventMeshIp, Integer.parseInt(destEventMeshPort), - session, clientSessionGroupMapping); - } - } - } - } catch (Exception e) { - logger.error("clientManage|redirectClientBySubSystem|fail|dcn={}|subSystem={}|destEventMeshIp" + - "={}|destEventMeshPort={},errMsg={}", dcn, subSystem, destEventMeshIp, destEventMeshPort, e); - result = String.format("redirectClientBySubSystem fail! sessionMap size {%d}, {clientIp=%s clientPort=%s " + - "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", - sessionMap.size(), dcn, subSystem, destEventMeshIp, destEventMeshPort, redirectResult, e - .getMessage()); - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - return; - } - result = String.format("redirectClientBySubSystem success! sessionMap size {%d}, {dcn=%s subSystem=%s " + - "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", - sessionMap.size(), dcn, subSystem, destEventMeshIp, destEventMeshPort, redirectResult); - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - } catch (Exception e) { - logger.error("redirectClientBySubSystem fail...", e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - logger.warn("out close failed...", e); - } - } - } - - } - } - - /** - * redirect subsystem for path - * - * @return - */ - class RedirectClientByPathHandler implements HttpHandler { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - String result = ""; - OutputStream out = httpExchange.getResponseBody(); - try { - String queryString = httpExchange.getRequestURI().getQuery(); - Map queryStringInfo = formData2Dic(queryString); - String path = queryStringInfo.get(EventMeshConstants.MANAGE_PATH); - String destEventMeshIp = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_IP); - String destEventMeshPort = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_PORT); - - if (StringUtils.isBlank(path) || StringUtils.isBlank(destEventMeshIp) || StringUtils.isBlank(destEventMeshPort) || - !StringUtils.isNumeric(destEventMeshPort)) { - httpExchange.sendResponseHeaders(200, 0); - result = "params illegal!"; - out.write(result.getBytes()); - return; - } - logger.info("redirectClientByPath in admin,path:{},destIp:{},destPort:{}====================", path, destEventMeshIp, destEventMeshPort); - ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); - ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); - String redirectResult = ""; - try { - if (!sessionMap.isEmpty()) { - for (Session session : sessionMap.values()) { - if (session.getClient().getPath().contains(path)) { - redirectResult += "|"; - redirectResult += EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer, destEventMeshIp, Integer.parseInt(destEventMeshPort), - session, clientSessionGroupMapping); - } - } - } - } catch (Exception e) { - logger.error("clientManage|redirectClientByPath|fail|path={}|destEventMeshIp" + - "={}|destEventMeshPort={},errMsg={}", path, destEventMeshIp, destEventMeshPort, e); - result = String.format("redirectClientByPath fail! sessionMap size {%d}, {path=%s " + - "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", - sessionMap.size(), path, destEventMeshIp, destEventMeshPort, redirectResult, e - .getMessage()); - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - return; - } - result = String.format("redirectClientByPath success! sessionMap size {%d}, {path=%s " + - "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", - sessionMap.size(), path, destEventMeshIp, destEventMeshPort, redirectResult); - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - } catch (Exception e) { - logger.error("redirectClientByPath fail...", e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - logger.warn("out close failed...", e); - } - } - } - - } - } - - /** - * redirect subsystem for ip and port - * - * @return - */ - class RedirectClientByIpPortHandler implements HttpHandler { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - String result = ""; - OutputStream out = httpExchange.getResponseBody(); - try { - String queryString = httpExchange.getRequestURI().getQuery(); - Map queryStringInfo = formData2Dic(queryString); - String ip = queryStringInfo.get(EventMeshConstants.MANAGE_IP); - String port = queryStringInfo.get(EventMeshConstants.MANAGE_PORT); - String destEventMeshIp = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_IP); - String destEventMeshPort = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_PORT); - - if (StringUtils.isBlank(ip) || !StringUtils.isNumeric(port) - || StringUtils.isBlank(destEventMeshIp) || StringUtils.isBlank(destEventMeshPort) - || !StringUtils.isNumeric(destEventMeshPort)) { - httpExchange.sendResponseHeaders(200, 0); - result = "params illegal!"; - out.write(result.getBytes()); - return; - } - logger.info("redirectClientByIpPort in admin,ip:{},port:{},destIp:{},destPort:{}====================", ip, port, destEventMeshIp, destEventMeshPort); - ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); - ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); - String redirectResult = ""; - try { - if (!sessionMap.isEmpty()) { - for (Session session : sessionMap.values()) { - if (session.getClient().getHost().equals(ip) && String.valueOf(session.getClient().getPort()).equals(port)) { - redirectResult += "|"; - redirectResult += EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer, destEventMeshIp, Integer.parseInt(destEventMeshPort), - session, clientSessionGroupMapping); - } - } - } - } catch (Exception e) { - logger.error("clientManage|redirectClientByIpPort|fail|ip={}|port={}|destEventMeshIp" + - "={}|destEventMeshPort={},errMsg={}", ip, port, destEventMeshIp, destEventMeshPort, e); - result = String.format("redirectClientByIpPort fail! sessionMap size {%d}, {clientIp=%s clientPort=%s " + - "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", - sessionMap.size(), ip, port, destEventMeshIp, destEventMeshPort, redirectResult, e - .getMessage()); - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - return; - } - result = String.format("redirectClientByIpPort success! sessionMap size {%d}, {ip=%s port=%s " + - "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", - sessionMap.size(), ip, port, destEventMeshIp, destEventMeshPort, redirectResult); - httpExchange.sendResponseHeaders(200, 0); - out.write(result.getBytes()); - } catch (Exception e) { - logger.error("redirectClientByIpPort fail...", e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - logger.warn("out close failed...", e); - } - } - } - - } - } - - private String printClients(List clients) { - if (clients.isEmpty()) { - return "no session had been closed"; - } - StringBuilder sb = new StringBuilder(); - for (InetSocketAddress addr : clients) { - sb.append(addr).append("|"); - } - return sb.toString(); - } - - private Map formData2Dic(String formData) { - Map result = new HashMap<>(); - if (formData == null || formData.trim().length() == 0) { - return result; - } - final String[] items = formData.split("&"); - Arrays.stream(items).forEach(item -> { - final String[] keyAndVal = item.split("="); - if (keyAndVal.length == 2) { - try { - final String key = URLDecoder.decode(keyAndVal[0], "utf8"); - final String val = URLDecoder.decode(keyAndVal[1], "utf8"); - result.put(key, val); - } catch (UnsupportedEncodingException e) { - logger.warn("formData2Dic:param decode failed...", e); - } - } - }); - return result; - } - - class EventMeshMsgDownStreamHandler implements HttpHandler { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - String result = "false"; - OutputStream out = httpExchange.getResponseBody(); - try { -// Map queryStringInfo = parsePostParameters(httpExchange); -// String msgStr = (String)queryStringInfo.get("msg"); -// String groupName = (String)queryStringInfo.get("group"); -// logger.info("recieve msg from other eventMesh, group:{}, msg:{}", groupName, msgStr); -// if (StringUtils.isBlank(msgStr) || StringUtils.isBlank(groupName)) { -// logger.warn("msg or groupName is null"); -// httpExchange.sendResponseHeaders(200, 0); -// out.write(result.getBytes()); -// return; -// } -// MessageExt messageExt = JSON.parseObject(msgStr, MessageExt.class); -// String topic = messageExt.getTopic(); -// -// if (!EventMeshUtil.isValidRMBTopic(topic)) { -// logger.warn("msg topic is illegal"); -// httpExchange.sendResponseHeaders(200, 0); -// out.write(result.getBytes()); -// return; -// } -// -// DownstreamDispatchStrategy downstreamDispatchStrategy = eventMeshTCPServer.getClientSessionGroupMapping().getClientGroupWrapper(groupName).getDownstreamDispatchStrategy(); -// Set groupConsumerSessions = eventMeshTCPServer.getClientSessionGroupMapping().getClientGroupWrapper(groupName).getGroupConsumerSessions(); -// Session session = downstreamDispatchStrategy.select(groupName, topic, groupConsumerSessions); -// -// if(session == null){ -// logger.error("DownStream msg,retry other eventMesh found no session again"); -// httpExchange.sendResponseHeaders(200, 0); -// out.write(result.getBytes()); -// return; -// } -// -// DownStreamMsgContext downStreamMsgContext = -// new DownStreamMsgContext(messageExt, session, eventMeshTCPServer.getClientSessionGroupMapping().getClientGroupWrapper(groupName).getPersistentMsgConsumer(), null, true); -// eventMeshTCPServer.getClientSessionGroupMapping().getClientGroupWrapper(groupName).getDownstreamMap().putIfAbsent(downStreamMsgContext.seq, downStreamMsgContext); -// -// if (session.isCanDownStream()) { -// session.downstreamMsg(downStreamMsgContext); -// httpExchange.sendResponseHeaders(200, 0); -// result = "true"; -// out.write(result.getBytes()); -// return; -// } -// -// logger.warn("EventMeshMsgDownStreamHandler|dispatch retry, seq[{}]", downStreamMsgContext.seq); -// long delayTime = EventMeshUtil.isService(downStreamMsgContext.msgExt.getTopic()) ? 0 : eventMeshTCPServer.getAccessConfiguration().eventMeshTcpMsgRetryDelayInMills; -// downStreamMsgContext.delay(delayTime); -// eventMeshTCPServer.getEventMeshTcpRetryer().pushRetry(downStreamMsgContext); -// result = "true"; -// httpExchange.sendResponseHeaders(200, 0); -// out.write(result.getBytes()); - - } catch (Exception e) { - logger.error("EventMeshMsgDownStreamHandler handle fail...", e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - logger.warn("out close failed...", e); - } - } - } - - } - } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java new file mode 100644 index 0000000000..79ba4bd98f --- /dev/null +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.runtime.admin.handler; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import org.apache.commons.lang3.StringUtils; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; +import org.apache.eventmesh.runtime.util.NetUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class RedirectClientByIpPortHandler implements HttpHandler { + + private static final Logger logger = LoggerFactory.getLogger(RedirectClientByIpPortHandler.class); + + private final EventMeshTCPServer eventMeshTCPServer; + + public RedirectClientByIpPortHandler(EventMeshTCPServer eventMeshTCPServer) { + this.eventMeshTCPServer = eventMeshTCPServer; + } + + @Override + public void handle(HttpExchange httpExchange) throws IOException { + String result = ""; + OutputStream out = httpExchange.getResponseBody(); + try { + String queryString = httpExchange.getRequestURI().getQuery(); + Map queryStringInfo = NetUtils.formData2Dic(queryString); + String ip = queryStringInfo.get(EventMeshConstants.MANAGE_IP); + String port = queryStringInfo.get(EventMeshConstants.MANAGE_PORT); + String destEventMeshIp = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_IP); + String destEventMeshPort = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_PORT); + + if (StringUtils.isBlank(ip) || !StringUtils.isNumeric(port) + || StringUtils.isBlank(destEventMeshIp) || StringUtils.isBlank(destEventMeshPort) + || !StringUtils.isNumeric(destEventMeshPort)) { + httpExchange.sendResponseHeaders(200, 0); + result = "params illegal!"; + out.write(result.getBytes()); + return; + } + logger.info("redirectClientByIpPort in admin,ip:{},port:{},destIp:{},destPort:{}====================", ip, port, destEventMeshIp, destEventMeshPort); + ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); + ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); + String redirectResult = ""; + try { + if (!sessionMap.isEmpty()) { + for (Session session : sessionMap.values()) { + if (session.getClient().getHost().equals(ip) && String.valueOf(session.getClient().getPort()).equals(port)) { + redirectResult += "|"; + redirectResult += EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer, destEventMeshIp, Integer.parseInt(destEventMeshPort), + session, clientSessionGroupMapping); + } + } + } + } catch (Exception e) { + logger.error("clientManage|redirectClientByIpPort|fail|ip={}|port={}|destEventMeshIp" + + "={}|destEventMeshPort={},errMsg={}", ip, port, destEventMeshIp, destEventMeshPort, e); + result = String.format("redirectClientByIpPort fail! sessionMap size {%d}, {clientIp=%s clientPort=%s " + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", + sessionMap.size(), ip, port, destEventMeshIp, destEventMeshPort, redirectResult, e + .getMessage()); + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + return; + } + result = String.format("redirectClientByIpPort success! sessionMap size {%d}, {ip=%s port=%s " + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", + sessionMap.size(), ip, port, destEventMeshIp, destEventMeshPort, redirectResult); + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + } catch (Exception e) { + logger.error("redirectClientByIpPort fail...", e); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + logger.warn("out close failed...", e); + } + } + } + + } +} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java new file mode 100644 index 0000000000..b605a1cc64 --- /dev/null +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.runtime.admin.handler; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import org.apache.commons.lang3.StringUtils; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; +import org.apache.eventmesh.runtime.util.NetUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * redirect subsystem for path + */ +public class RedirectClientByPathHandler implements HttpHandler { + + private static final Logger logger = LoggerFactory.getLogger(RedirectClientByPathHandler.class); + + private EventMeshTCPServer eventMeshTCPServer; + + public RedirectClientByPathHandler(EventMeshTCPServer eventMeshTCPServer) { + this.eventMeshTCPServer = eventMeshTCPServer; + } + + @Override + public void handle(HttpExchange httpExchange) throws IOException { + String result = ""; + OutputStream out = httpExchange.getResponseBody(); + try { + String queryString = httpExchange.getRequestURI().getQuery(); + Map queryStringInfo = NetUtils.formData2Dic(queryString); + String path = queryStringInfo.get(EventMeshConstants.MANAGE_PATH); + String destEventMeshIp = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_IP); + String destEventMeshPort = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_PORT); + + if (StringUtils.isBlank(path) || StringUtils.isBlank(destEventMeshIp) || StringUtils.isBlank(destEventMeshPort) || + !StringUtils.isNumeric(destEventMeshPort)) { + httpExchange.sendResponseHeaders(200, 0); + result = "params illegal!"; + out.write(result.getBytes()); + return; + } + logger.info("redirectClientByPath in admin,path:{},destIp:{},destPort:{}====================", path, destEventMeshIp, destEventMeshPort); + ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); + ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); + String redirectResult = ""; + try { + if (!sessionMap.isEmpty()) { + for (Session session : sessionMap.values()) { + if (session.getClient().getPath().contains(path)) { + redirectResult += "|"; + redirectResult += EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer, destEventMeshIp, Integer.parseInt(destEventMeshPort), + session, clientSessionGroupMapping); + } + } + } + } catch (Exception e) { + logger.error("clientManage|redirectClientByPath|fail|path={}|destEventMeshIp" + + "={}|destEventMeshPort={},errMsg={}", path, destEventMeshIp, destEventMeshPort, e); + result = String.format("redirectClientByPath fail! sessionMap size {%d}, {path=%s " + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", + sessionMap.size(), path, destEventMeshIp, destEventMeshPort, redirectResult, e + .getMessage()); + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + return; + } + result = String.format("redirectClientByPath success! sessionMap size {%d}, {path=%s " + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", + sessionMap.size(), path, destEventMeshIp, destEventMeshPort, redirectResult); + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + } catch (Exception e) { + logger.error("redirectClientByPath fail...", e); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + logger.warn("out close failed...", e); + } + } + } + + } +} \ No newline at end of file diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java new file mode 100644 index 0000000000..400c8c0e8e --- /dev/null +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.runtime.admin.handler; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import org.apache.commons.lang3.StringUtils; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; +import org.apache.eventmesh.runtime.util.NetUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * redirect subsystem for subsys and dcn + */ +public class RedirectClientBySubSystemHandler implements HttpHandler { + + private static final Logger logger = LoggerFactory.getLogger(RedirectClientBySubSystemHandler.class); + + private final EventMeshTCPServer eventMeshTCPServer; + + public RedirectClientBySubSystemHandler(EventMeshTCPServer eventMeshTCPServer) { + this.eventMeshTCPServer = eventMeshTCPServer; + } + + @Override + public void handle(HttpExchange httpExchange) throws IOException { + String result = ""; + OutputStream out = httpExchange.getResponseBody(); + try { + String queryString = httpExchange.getRequestURI().getQuery(); + Map queryStringInfo = NetUtils.formData2Dic(queryString); + String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM); + String destEventMeshIp = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_IP); + String destEventMeshPort = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_PORT); + + if (!StringUtils.isNumeric(subSystem) + || StringUtils.isBlank(destEventMeshIp) || StringUtils.isBlank(destEventMeshPort) + || !StringUtils.isNumeric(destEventMeshPort)) { + httpExchange.sendResponseHeaders(200, 0); + result = "params illegal!"; + out.write(result.getBytes()); + return; + } + logger.info("redirectClientBySubSystem in admin,subsys:{},destIp:{},destPort:{}====================", subSystem, destEventMeshIp, destEventMeshPort); + ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); + ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); + String redirectResult = ""; + try { + if (!sessionMap.isEmpty()) { + for (Session session : sessionMap.values()) { + if (session.getClient().getSubsystem().equals(subSystem)) { + redirectResult += "|"; + redirectResult += EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer, destEventMeshIp, Integer.parseInt(destEventMeshPort), + session, clientSessionGroupMapping); + } + } + } + } catch (Exception e) { + logger.error("clientManage|redirectClientBySubSystem|fail|subSystem={}|destEventMeshIp" + + "={}|destEventMeshPort={},errMsg={}", subSystem, destEventMeshIp, destEventMeshPort, e); + result = String.format("redirectClientBySubSystem fail! sessionMap size {%d}, {subSystem=%s " + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", + sessionMap.size(), subSystem, destEventMeshIp, destEventMeshPort, redirectResult, e + .getMessage()); + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + return; + } + result = String.format("redirectClientBySubSystem success! sessionMap size {%d}, {subSystem=%s " + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", + sessionMap.size(), subSystem, destEventMeshIp, destEventMeshPort, redirectResult); + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + } catch (Exception e) { + logger.error("redirectClientBySubSystem fail...", e); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + logger.warn("out close failed...", e); + } + } + } + } +} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java new file mode 100644 index 0000000000..6314c489ac --- /dev/null +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.runtime.admin.handler; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; +import org.apache.eventmesh.runtime.util.NetUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class RejectAllClientHandler implements HttpHandler { + + private static final Logger logger = LoggerFactory.getLogger(RejectAllClientHandler.class); + + private final EventMeshTCPServer eventMeshTCPServer; + + public RejectAllClientHandler(EventMeshTCPServer eventMeshTCPServer) { + this.eventMeshTCPServer = eventMeshTCPServer; + } + + /** + * remove all clients accessed by eventMesh + * + * @param httpExchange + * @throws IOException + */ + @Override + public void handle(HttpExchange httpExchange) throws IOException { + String result = ""; + OutputStream out = httpExchange.getResponseBody(); + try { + ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); + ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); + final List successRemoteAddrs = new ArrayList<>(); + try { + logger.info("rejectAllClient in admin===================="); + if (!sessionMap.isEmpty()) { + for (Map.Entry entry : sessionMap.entrySet()) { + InetSocketAddress addr = EventMeshTcp2Client.serverGoodby2Client(eventMeshTCPServer, entry.getValue(), clientSessionGroupMapping); + if (addr != null) { + successRemoteAddrs.add(addr); + } + } + } + } catch (Exception e) { + logger.error("clientManage|rejectAllClient|fail", e); + result = String.format("rejectAllClient fail! sessionMap size {%d}, had reject {%s}, errorMsg : %s", + sessionMap.size(), NetUtils.addressToString(successRemoteAddrs), e.getMessage()); + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + return; + } + result = String.format("rejectAllClient success! sessionMap size {%d}, had reject {%s}", sessionMap.size(), + NetUtils.addressToString(successRemoteAddrs)); + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + } catch (Exception e) { + logger.error("rejectAllClient fail...", e); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + logger.warn("out close failed...", e); + } + } + } + } +} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java new file mode 100644 index 0000000000..3ddd45e492 --- /dev/null +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.runtime.admin.handler; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import org.apache.commons.lang3.StringUtils; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; +import org.apache.eventmesh.runtime.util.NetUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class RejectClientByIpPortHandler implements HttpHandler { + + private static final Logger logger = LoggerFactory.getLogger(RejectClientByIpPortHandler.class); + + private EventMeshTCPServer eventMeshTCPServer; + + public RejectClientByIpPortHandler(EventMeshTCPServer eventMeshTCPServer) { + this.eventMeshTCPServer = eventMeshTCPServer; + } + + @Override + public void handle(HttpExchange httpExchange) throws IOException { + String result = ""; + OutputStream out = httpExchange.getResponseBody(); + try { + String queryString = httpExchange.getRequestURI().getQuery(); + Map queryStringInfo = NetUtils.formData2Dic(queryString); + String ip = queryStringInfo.get(EventMeshConstants.MANAGE_IP); + String port = queryStringInfo.get(EventMeshConstants.MANAGE_PORT); + + if (StringUtils.isBlank(ip) || StringUtils.isBlank(port)) { + httpExchange.sendResponseHeaders(200, 0); + result = "params illegal!"; + out.write(result.getBytes()); + return; + } + logger.info("rejectClientByIpPort in admin,ip:{},port:{}====================", ip, port); + ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); + ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); + final List successRemoteAddrs = new ArrayList(); + try { + if (!sessionMap.isEmpty()) { + for (Map.Entry entry : sessionMap.entrySet()) { + if (entry.getKey().getHostString().equals(ip) && String.valueOf(entry.getKey().getPort()).equals(port)) { + InetSocketAddress addr = EventMeshTcp2Client.serverGoodby2Client(eventMeshTCPServer, entry.getValue(), clientSessionGroupMapping); + if (addr != null) { + successRemoteAddrs.add(addr); + } + } + } + } + } catch (Exception e) { + logger.error("clientManage|rejectClientByIpPort|fail|ip={}|port={},errMsg={}", ip, port, e); + result = String.format("rejectClientByIpPort fail! {ip=%s port=%s}, had reject {%s}, errorMsg : %s", ip, + port, NetUtils.addressToString(successRemoteAddrs), e.getMessage()); + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + return; + } + + result = String.format("rejectClientByIpPort success! {ip=%s port=%s}, had reject {%s}", ip, port, + NetUtils.addressToString(successRemoteAddrs)); + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + } catch (Exception e) { + logger.error("rejectClientByIpPort fail...", e); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + logger.warn("out close failed...", e); + } + } + } + + } +} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java new file mode 100644 index 0000000000..e5208c665c --- /dev/null +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.runtime.admin.handler; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import org.apache.commons.lang3.StringUtils; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; +import org.apache.eventmesh.runtime.util.NetUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class RejectClientBySubSystemHandler implements HttpHandler { + + private static final Logger logger = LoggerFactory.getLogger(RejectClientBySubSystemHandler.class); + + private EventMeshTCPServer eventMeshTCPServer; + + public RejectClientBySubSystemHandler(EventMeshTCPServer eventMeshTCPServer) { + this.eventMeshTCPServer = eventMeshTCPServer; + } + + private String printClients(List clients) { + if (clients.isEmpty()) { + return "no session had been closed"; + } + StringBuilder sb = new StringBuilder(); + for (InetSocketAddress addr : clients) { + sb.append(addr).append("|"); + } + return sb.toString(); + } + + /** + * remove c client by dcn and susysId + * @param httpExchange + * @throws IOException + */ + @Override + public void handle(HttpExchange httpExchange) throws IOException { + String result = ""; + OutputStream out = httpExchange.getResponseBody(); + try { + String queryString = httpExchange.getRequestURI().getQuery(); + Map queryStringInfo = NetUtils.formData2Dic(queryString); + String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM); + + if (StringUtils.isBlank(subSystem)) { + httpExchange.sendResponseHeaders(200, 0); + result = "params illegal!"; + out.write(result.getBytes()); + return; + } + + logger.info("rejectClientBySubSystem in admin,subsys:{}====================", subSystem); + ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); + ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); + final List successRemoteAddrs = new ArrayList(); + try { + if (!sessionMap.isEmpty()) { + for (Session session : sessionMap.values()) { + if (session.getClient().getSubsystem().equals(subSystem)) { + InetSocketAddress addr = EventMeshTcp2Client.serverGoodby2Client(eventMeshTCPServer, session, clientSessionGroupMapping); + if (addr != null) { + successRemoteAddrs.add(addr); + } + } + } + } + } catch (Exception e) { + logger.error("clientManage|rejectClientBySubSystem|fail|subSystemId={},errMsg={}", subSystem, e); + result = String.format("rejectClientBySubSystem fail! sessionMap size {%d}, had reject {%d} , {" + + "subSystemId=%s}, errorMsg : %s", sessionMap.size(), printClients(successRemoteAddrs), subSystem, e.getMessage()); + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + return; + } + result = String.format("rejectClientBySubSystem success! sessionMap size {%d}, had reject {%s} , {" + + "subSystemId=%s}", sessionMap.size(), printClients(successRemoteAddrs), subSystem); + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + } catch (Exception e) { + logger.error("rejectClientBySubSystem fail...", e); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + logger.warn("out close failed...", e); + } + } + } + + } +} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java new file mode 100644 index 0000000000..07cbbb20c8 --- /dev/null +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.runtime.admin.handler; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; +import org.apache.eventmesh.runtime.util.NetUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class ShowClientBySystemHandler implements HttpHandler { + + private static final Logger logger = LoggerFactory.getLogger(ShowClientBySystemHandler.class); + + private final EventMeshTCPServer eventMeshTCPServer; + + public ShowClientBySystemHandler(EventMeshTCPServer eventMeshTCPServer) { + this.eventMeshTCPServer = eventMeshTCPServer; + } + + /** + * print clientInfo by subsys + * + * @param httpExchange + * @throws IOException + */ + @Override + public void handle(HttpExchange httpExchange) throws IOException { + String result = ""; + OutputStream out = httpExchange.getResponseBody(); + try { + String queryString = httpExchange.getRequestURI().getQuery(); + Map queryStringInfo = NetUtils.formData2Dic(queryString); + String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM); + + String newLine = System.getProperty("line.separator"); + logger.info("showClientBySubsys,subsys:{}=================", subSystem); + ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); + ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); + if (!sessionMap.isEmpty()) { + for (Session session : sessionMap.values()) { + if (session.getClient().getSubsystem().equals(subSystem)) { + UserAgent userAgent = session.getClient(); + result += String.format("pid=%s | ip=%s | port=%s | path=%s | purpose=%s", userAgent.getPid(), userAgent + .getHost(), userAgent.getPort(), userAgent.getPath(), userAgent.getPurpose()) + newLine; + } + } + } + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + } catch (Exception e) { + logger.error("ShowClientBySystemAndHandler fail...", e); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + logger.warn("out close failed...", e); + } + } + } + } + + +} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java new file mode 100644 index 0000000000..64d5c5df04 --- /dev/null +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.runtime.admin.handler; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * This handler used to print the total client info + */ +public class ShowClientHandler implements HttpHandler { + + private static final Logger logger = LoggerFactory.getLogger(ShowClientHandler.class); + + private final EventMeshTCPServer eventMeshTCPServer; + + public ShowClientHandler(EventMeshTCPServer eventMeshTCPServer) { + this.eventMeshTCPServer = eventMeshTCPServer; + } + + @Override + public void handle(HttpExchange httpExchange) throws IOException { + String result = ""; + OutputStream out = httpExchange.getResponseBody(); + try { + String newLine = System.getProperty("line.separator"); + logger.info("showAllClient================="); + ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); + + HashMap statMap = new HashMap(); + + Map sessionMap = clientSessionGroupMapping.getSessionMap(); + if (!sessionMap.isEmpty()) { + for (Session session : sessionMap.values()) { + String key = session.getClient().getSubsystem(); + if (!statMap.containsKey(key)) { + statMap.put(key, new AtomicInteger(1)); + } else { + statMap.get(key).incrementAndGet(); + } + } + + for (Map.Entry entry : statMap.entrySet()) { + result += String.format("System=%s | ClientNum=%d", entry.getKey(), entry.getValue().intValue()) + + newLine; + } + } + + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + } catch (Exception e) { + logger.error("ShowClientHandler fail...", e); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + logger.warn("out close failed...", e); + } + } + } + + } +} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java new file mode 100644 index 0000000000..6d8cbe4bcc --- /dev/null +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.runtime.admin.handler; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientGroupWrapper; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; +import org.apache.eventmesh.runtime.util.NetUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * query client subscription by topic + */ +public class ShowListenClientByTopicHandler implements HttpHandler { + + private Logger logger = LoggerFactory.getLogger(ShowListenClientByTopicHandler.class); + + private final EventMeshTCPServer eventMeshTCPServer; + + public ShowListenClientByTopicHandler(EventMeshTCPServer eventMeshTCPServer) { + this.eventMeshTCPServer = eventMeshTCPServer; + } + + @Override + public void handle(HttpExchange httpExchange) throws IOException { + String result = ""; + OutputStream out = httpExchange.getResponseBody(); + try { + String queryString = httpExchange.getRequestURI().getQuery(); + Map queryStringInfo = NetUtils.formData2Dic(queryString); + String topic = queryStringInfo.get(EventMeshConstants.MANAGE_TOPIC); + + String newLine = System.getProperty("line.separator"); + logger.info("showListeningClientByTopic,topic:{}=================", topic); + ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); + ConcurrentHashMap clientGroupMap = clientSessionGroupMapping.getClientGroupMap(); + if (!clientGroupMap.isEmpty()) { + for (ClientGroupWrapper cgw : clientGroupMap.values()) { + Set listenSessionSet = cgw.getTopic2sessionInGroupMapping().get(topic); + if (listenSessionSet != null && listenSessionSet.size() > 0) { + result += String.format("group:%s", cgw.getConsumerGroup()) + newLine; + for (Session session : listenSessionSet) { + UserAgent userAgent = session.getClient(); + result += String.format("pid=%s | ip=%s | port=%s | path=%s | version=%s", userAgent.getPid(), userAgent + .getHost(), userAgent.getPort(), userAgent.getPath(), userAgent.getVersion()) + newLine; + } + } + } + } + httpExchange.sendResponseHeaders(200, 0); + out.write(result.getBytes()); + } catch (Exception e) { + logger.error("ShowListenClientByTopicHandler fail...", e); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + logger.warn("out close failed...", e); + } + } + } + + } +} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbrstractHTTPServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbrstractHTTPServer.java index d7816e98bc..4e902a6d9d 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbrstractHTTPServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbrstractHTTPServer.java @@ -84,7 +84,7 @@ public abstract class AbrstractHTTPServer extends AbstractRemotingServer { - public Logger logger = LoggerFactory.getLogger(this.getClass()); + public Logger httpServerLogger = LoggerFactory.getLogger(this.getClass()); public Logger httpLogger = LoggerFactory.getLogger("http"); @@ -158,15 +158,15 @@ public void start() throws Exception { .channel(NioServerSocketChannel.class) .childHandler(new HttpsServerInitializer(SSLContextFactory.getSslContext())).childOption(ChannelOption.SO_KEEPALIVE, Boolean.TRUE); try { - logger.info("HTTPServer[port={}] started......", this.port); + httpServerLogger.info("HTTPServer[port={}] started......", this.port); ChannelFuture future = b.bind(this.port).sync(); future.channel().closeFuture().sync(); } catch (Exception e) { - logger.error("HTTPServer start Err!", e); + httpServerLogger.error("HTTPServer start Err!", e); try { shutdown(); } catch (Exception e1) { - logger.error("HTTPServer shutdown Err!", e); + httpServerLogger.error("HTTPServer shutdown Err!", e); } return; } @@ -290,7 +290,7 @@ protected void channelRead0(ChannelHandlerContext ctx, HttpRequest httpRequest) AsyncContext asyncContext = new AsyncContext(requestCommand, responseCommand, asyncContextCompleteHandler); processEventMeshRequest(ctx, asyncContext); } catch (Exception ex) { - logger.error("AbrstractHTTPServer.HTTPHandler.channelRead0 err", ex); + httpServerLogger.error("AbrstractHTTPServer.HTTPHandler.channelRead0 err", ex); } finally { try { decoder.destroy(); @@ -330,7 +330,7 @@ public void processEventMeshRequest(final ChannelHandlerContext ctx, sendResponse(ctx, asyncContext.getResponse().httpResponse()); } catch (Exception e) { - logger.error("process error", e); + httpServerLogger.error("process error", e); } }); } catch (RejectedExecutionException re) { @@ -376,7 +376,7 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); int c = connections.incrementAndGet(); if (c > 20000) { - logger.warn("client|http|channelActive|remoteAddress={}|msg={}", remoteAddress, "too many client(20000) connect " + + httpServerLogger.warn("client|http|channelActive|remoteAddress={}|msg={}", remoteAddress, "too many client(20000) connect " + "this eventMesh server"); ctx.close(); return; @@ -399,7 +399,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc IdleStateEvent event = (IdleStateEvent) evt; if (event.state().equals(IdleState.ALL_IDLE)) { final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); - logger.info("client|http|userEventTriggered|remoteAddress={}|msg={}", remoteAddress, evt.getClass() + httpServerLogger.info("client|http|userEventTriggered|remoteAddress={}|msg={}", remoteAddress, evt.getClass() .getName()); ctx.close(); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshHTTPServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshHTTPServer.java index 80540c0d75..84a2ab79b0 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshHTTPServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshHTTPServer.java @@ -54,9 +54,9 @@ public class EventMeshHTTPServer extends AbrstractHTTPServer { private EventMeshHTTPConfiguration eventMeshHttpConfiguration; - public final ConcurrentHashMap localConsumerGroupMapping = new ConcurrentHashMap<>(); + public final ConcurrentHashMap localConsumerGroupMapping = new ConcurrentHashMap<>(); - public final ConcurrentHashMap> localClientInfoMapping = new ConcurrentHashMap<>(); + public final ConcurrentHashMap> localClientInfoMapping = new ConcurrentHashMap<>(); public EventMeshHTTPServer(EventMeshServer eventMeshServer, EventMeshHTTPConfiguration eventMeshHttpConfiguration) { diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java index 61bfb89bdb..19d69533ef 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java @@ -54,7 +54,6 @@ public void init() throws Exception { String eventstore = System.getProperty(EventMeshConstants.EVENT_STORE_PROPERTIES, System.getenv(EventMeshConstants.EVENT_STORE_ENV)); logger.info("eventstore : {}", eventstore); -// logger.info("load custom {} class for eventMesh", ConsumeMessageConcurrentlyService.class.getCanonicalName()); serviceState = ServiceState.INITED; logger.info("server state:{}", serviceState); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshTCPServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshTCPServer.java index 84454d10b7..12f37d3300 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshTCPServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshTCPServer.java @@ -26,11 +26,7 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.PooledByteBufAllocator; -import io.netty.channel.AdaptiveRecvByteBufAllocator; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelOption; +import io.netty.channel.*; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.timeout.IdleStateHandler; import io.netty.handler.traffic.ChannelTrafficShapingHandler; @@ -68,6 +64,8 @@ public class EventMeshTCPServer extends AbstractRemotingServer { private ExecutorService taskHandleExecutorService; + private ExecutorService broadcastMsgDownstreamExecutorService; + public void setClientSessionGroupMapping(ClientSessionGroupMapping clientSessionGroupMapping) { this.clientSessionGroupMapping = clientSessionGroupMapping; } @@ -92,6 +90,10 @@ public ExecutorService getTaskHandleExecutorService() { return taskHandleExecutorService; } + public ExecutorService getBroadcastMsgDownstreamExecutorService() { + return broadcastMsgDownstreamExecutorService; + } + public void setTaskHandleExecutorService(ExecutorService taskHandleExecutorService) { this.taskHandleExecutorService = taskHandleExecutorService; } @@ -108,10 +110,6 @@ public void setRateLimiter(RateLimiter rateLimiter) { private RateLimiter rateLimiter; - private EventMeshTcpMessageDispatcher eventMeshTcpMessageDispatcher = new EventMeshTcpMessageDispatcher(EventMeshTCPServer.this); - private EventMeshTcpExceptionHandler eventMeshTcpExceptionHandler = new EventMeshTcpExceptionHandler(EventMeshTCPServer.this); - - public EventMeshTCPServer(EventMeshServer eventMeshServer, EventMeshTCPConfiguration eventMeshTCPConfiguration) { super(); @@ -147,8 +145,8 @@ public void initChannel(Channel ch) throws Exception { .addLast(workerGroup, new IdleStateHandler(eventMeshTCPConfiguration.eventMeshTcpIdleReadSeconds, eventMeshTCPConfiguration.eventMeshTcpIdleWriteSeconds, eventMeshTCPConfiguration.eventMeshTcpIdleAllSeconds), - eventMeshTcpMessageDispatcher, - eventMeshTcpExceptionHandler + new EventMeshTcpMessageDispatcher(EventMeshTCPServer.this), + new EventMeshTcpExceptionHandler(EventMeshTCPServer.this) ); } }); @@ -248,7 +246,8 @@ private void initThreadPool() throws Exception { scheduler = ThreadPoolFactory.createScheduledExecutor(eventMeshTCPConfiguration.eventMeshTcpGlobalScheduler, new EventMeshThreadFactoryImpl("eventMesh-tcp-scheduler", true)); taskHandleExecutorService = ThreadPoolFactory.createThreadPoolExecutor(eventMeshTCPConfiguration.eventMeshTcpTaskHandleExecutorPoolSize, eventMeshTCPConfiguration.eventMeshTcpTaskHandleExecutorPoolSize, new LinkedBlockingQueue(10000), new EventMeshThreadFactoryImpl("eventMesh-tcp-task-handle", true)); - ; + + broadcastMsgDownstreamExecutorService = ThreadPoolFactory.createThreadPoolExecutor(eventMeshTCPConfiguration.eventMeshTcpMsgDownStreamExecutorPoolSize, eventMeshTCPConfiguration.eventMeshTcpMsgDownStreamExecutorPoolSize, new LinkedBlockingQueue(10000), new EventMeshThreadFactoryImpl("eventMesh-tcp-msg-downstream", true)); } private void shutdownThreadPool() { diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfiguration.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfiguration.java index 4f3ddddf5e..975edf8af9 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfiguration.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfiguration.java @@ -49,12 +49,12 @@ public class EventMeshTCPConfiguration extends CommonConfiguration { public int eventMeshTcpTaskHandleExecutorPoolSize = Runtime.getRuntime().availableProcessors(); + public int eventMeshTcpMsgDownStreamExecutorPoolSize = Runtime.getRuntime().availableProcessors() > 8 ? Runtime.getRuntime().availableProcessors() : 8; + public int eventMeshTcpSessionExpiredInMills = 60000; public int eventMeshTcpSessionUpstreamBufferSize = 100; - public int eventMeshTcpSessionDownstreamUnackSize = 12; - public int eventMeshTcpMsgRetryTimes = 3; public int eventMeshTcpMsgRetryDelayInMills = 500; @@ -71,8 +71,6 @@ public class EventMeshTCPConfiguration extends CommonConfiguration { public int eventMeshTcpPushFailIsolateTimeInMills = 30 * 1000; - public int eventMeshTcpDownStreamMapSize = 500; - private TrafficShapingConfig gtc = new TrafficShapingConfig(0, 10_000, 1_000, 2000); private TrafficShapingConfig ctc = new TrafficShapingConfig(0, 2_000, 1_000, 10_000); @@ -132,6 +130,13 @@ public void init() { eventMeshTcpTaskHandleExecutorPoolSize = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshTcpTaskHandleExecutorPoolSizeStr)); } + String eventMeshTcpMsgDownStreamExecutorPoolSizeStr = configurationWraper.getProp(ConfKeys.KEYS_EVENTMESH_SERVER_TCP_MSG_DOWNSTREAM_POOL_SIZE); + if(StringUtils.isNotEmpty(eventMeshTcpMsgDownStreamExecutorPoolSizeStr)){ + Preconditions.checkState(StringUtils.isNumeric(eventMeshTcpMsgDownStreamExecutorPoolSizeStr), + String.format("%s error", ConfKeys.KEYS_EVENTMESH_SERVER_TCP_MSG_DOWNSTREAM_POOL_SIZE)); + eventMeshTcpMsgDownStreamExecutorPoolSize = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshTcpMsgDownStreamExecutorPoolSizeStr)); + } + String eventMeshTcpSessionExpiredInMillsStr = configurationWraper.getProp(ConfKeys.KEYS_EVENTMESH_SERVER_SESSION_EXPIRED_TIME); if (StringUtils.isNotEmpty(eventMeshTcpSessionExpiredInMillsStr)) { Preconditions.checkState(StringUtils.isNumeric(eventMeshTcpSessionExpiredInMillsStr), String.format("%s error", ConfKeys.KEYS_EVENTMESH_SERVER_SESSION_EXPIRED_TIME)); @@ -145,12 +150,6 @@ public void init() { eventMeshTcpSessionUpstreamBufferSize = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshTcpSessionUpstreamBufferSizeStr)); } - String eventMeshTcpSessionDownstreamUnackSizeStr = configurationWraper.getProp(ConfKeys.KEYS_EVENTMESH_SERVER_SESSION_DOWNSTREAM_UNACK_SIZE); - if (StringUtils.isNotEmpty(eventMeshTcpSessionDownstreamUnackSizeStr)) { - Preconditions.checkState(StringUtils.isNumeric(eventMeshTcpSessionDownstreamUnackSizeStr), String.format("%s error", ConfKeys.KEYS_EVENTMESH_SERVER_SESSION_DOWNSTREAM_UNACK_SIZE)); - eventMeshTcpSessionDownstreamUnackSize = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshTcpSessionDownstreamUnackSizeStr)); - } - //========================================eventMesh retry config=============================================// String eventMeshTcpMsgRetryTimesStr = configurationWraper.getProp(ConfKeys.KEYS_EVENTMESH_SERVER_RETRY_PUSH_RETRY_TIMES); if (StringUtils.isNotEmpty(eventMeshTcpMsgRetryTimesStr)) { @@ -194,12 +193,6 @@ public void init() { Preconditions.checkState(StringUtils.isNumeric(eventMeshTcpPushFailIsolateTimeInMillsStr), String.format("%s error", ConfKeys.KEYS_EVENTMESH_SERVER_PUSH_FAIL_ISOLATE_TIME)); eventMeshTcpPushFailIsolateTimeInMills = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshTcpPushFailIsolateTimeInMillsStr)); } - - String eventMeshTcpDownStreamMapSizeStr = configurationWraper.getProp(ConfKeys.KEYS_EVENTMESH_TCP_DOWNSTREAM_MAP_SIZE); - if (StringUtils.isNotEmpty(eventMeshTcpDownStreamMapSizeStr)) { - Preconditions.checkState(StringUtils.isNumeric(eventMeshTcpDownStreamMapSizeStr), String.format("%s error", ConfKeys.KEYS_EVENTMESH_TCP_DOWNSTREAM_MAP_SIZE)); - eventMeshTcpDownStreamMapSize = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshTcpDownStreamMapSizeStr)); - } } public TrafficShapingConfig getGtc() { @@ -221,6 +214,7 @@ static class ConfKeys { public static String KEYS_EVENTMESH_SERVER_TCP_REBALANCE_INTERVAL = "eventMesh.server.tcp.RebalanceIntervalInMills"; public static String KEYS_EVENTMESH_SERVER_GLOBAL_SCHEDULER = "eventMesh.server.global.scheduler"; public static String KEYS_EVENTMESH_SERVER_TCP_TASK_HANDLE_POOL_SIZE = "eventMesh.server.tcp.taskHandleExecutorPoolSize"; + public static String KEYS_EVENTMESH_SERVER_TCP_MSG_DOWNSTREAM_POOL_SIZE = "eventMesh.server.tcp.msgDownStreamExecutorPoolSize"; public static String KEYS_EVENTMESH_SERVER_SESSION_EXPIRED_TIME = "eventMesh.server.session.expiredInMills"; public static String KEYS_EVENTMESH_SERVER_SESSION_UPSTREAM_BUFFER_SIZE = "eventMesh.server.session.upstreamBufferSize"; public static String KEYS_EVENTMESH_SERVER_SESSION_DOWNSTREAM_UNACK_SIZE = "eventMesh.server.session.downstreamUnackSize"; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/DeFiBusConstant.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/DeFiBusConstant.java deleted file mode 100644 index 898854d770..0000000000 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/DeFiBusConstant.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to Apache Software Foundation (ASF) under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Apache Software Foundation (ASF) licenses this file to you 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. - */ -package org.apache.eventmesh.runtime.constants; - -//TODO -public class DeFiBusConstant { - public static final String PROPERTY_MESSAGE_REPLY_TO = "REPLY_TO"; //requester clientId - - public static final String PROPERTY_RR_REQUEST_ID = "RR_REQUEST_UNIQ_ID"; - - public static final String PROPERTY_MESSAGE_TTL = "TTL"; //timeout for request-response - - public static final String PROPERTY_MESSAGE_CLUSTER = "CLUSTER"; //cluster name - - public static final String PROPERTY_MESSAGE_BROKER = "BROKER"; //broker name where message stored - - public static final String REDIRECT = "REDIRECT"; - - public static final String REDIRECT_FLAG = "REDIRECT_FLAG"; - - public static final String PLUGIN_CLASS_NAME = "org.apache.defibus.broker.plugin.DeFiPluginMessageStore"; - - public static final String RR_REPLY_TOPIC = "rr-reply-topic"; //post fix for reply topic - - public static final String KEY = "msgType"; - - public static final String DEFAULT_TTL = "14400000"; - - public static final String EXT_CONSUMER_GROUP = "ExtConsumerGroup"; - - public static final String RMQ_SYS = "RMQ_SYS_"; - - /** - * msgType1: indicate the msg is broadcast message - */ - public static final String DIRECT = "direct"; - - /** - * msgType2: msg of type except broadcast and reply - */ - public static final String PERSISTENT = "persistent"; - - /** - * msgType3: indicate the msg is which consumer reply to producer - */ - public static final String REPLY = "reply"; - - public static final String INSTANCE_NAME_SEPERATER = "#"; - - public static final String IDC_SEPERATER = "-"; - - public static final String LEAVE_TIME = "LEAVE_TIME"; //leaveBrokerTime - public static final String ARRIVE_TIME = "ARRIVE_TIME"; - public static final String STORE_TIME = "STORE_TIME"; - -} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/EventMeshConstants.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/EventMeshConstants.java index d498305e6c..6a5d35d3e4 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/EventMeshConstants.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/EventMeshConstants.java @@ -27,12 +27,6 @@ public class EventMeshConstants { public static final String PROTOCOL_TCP = "tcp"; - public static final String BROADCAST_PREFIX = "broadcast-"; - - public final static String CONSUMER_GROUP_NAME_PREFIX = "ConsumerGroup-"; - - public final static String PRODUCER_GROUP_NAME_PREFIX = "ProducerGroup-"; - public static final String DEFAULT_CHARSET = "UTF-8"; public static final String EVENTMESH_CONF_HOME = System.getProperty("confPath", System.getenv("confPath")); @@ -85,7 +79,6 @@ public class EventMeshConstants { public static final String TAG = "TAG"; - public static final String MANAGE_DCN = "dcn"; public static final String MANAGE_SUBSYSTEM = "subSystem"; public static final String MANAGE_IP = "ip"; public static final String MANAGE_PORT = "port"; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ConsumerGroupTopicConf.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ConsumerGroupTopicConf.java index 5a16c4c703..f29d90ae67 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ConsumerGroupTopicConf.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ConsumerGroupTopicConf.java @@ -25,6 +25,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,6 +37,11 @@ public class ConsumerGroupTopicConf { private String topic; + /** + * @see org.apache.eventmesh.common.protocol.SubscriptionItem + */ + private SubscriptionItem subscriptionItem; + /** * PUSH URL */ @@ -53,12 +59,13 @@ public boolean equals(Object o) { ConsumerGroupTopicConf that = (ConsumerGroupTopicConf) o; return consumerGroup.equals(that.consumerGroup) && Objects.equals(topic, that.topic) && + Objects.equals(subscriptionItem, that.subscriptionItem) && Objects.equals(idcUrls, that.idcUrls); } @Override public int hashCode() { - return Objects.hash(consumerGroup, topic, idcUrls); + return Objects.hash(consumerGroup, topic, subscriptionItem, idcUrls); } @Override @@ -66,6 +73,7 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("consumeTopicConfig={consumerGroup=").append(consumerGroup) .append(",topic=").append(topic) + .append(",subscriptionMode=").append(subscriptionItem) .append(",idcUrls=").append(idcUrls).append("}"); return sb.toString(); } @@ -86,6 +94,14 @@ public void setTopic(String topic) { this.topic = topic; } + public SubscriptionItem getSubscriptionItem() { + return subscriptionItem; + } + + public void setSubscriptionItem(SubscriptionItem subscriptionItem) { + this.subscriptionItem = subscriptionItem; + } + public Map> getIdcUrls() { return idcUrls; } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQConsumerWrapper.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQConsumerWrapper.java index ad44d3e9b9..080b7af40a 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQConsumerWrapper.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQConsumerWrapper.java @@ -43,14 +43,6 @@ public void unsubscribe(String topic) throws Exception { meshMQPushConsumer.unsubscribe(topic); } -// public boolean isPause() { -// return meshMQPushConsumer.isPause(); -// } -// -// public void pause() { -// meshMQPushConsumer.pause(); -// } - public synchronized void init(Properties keyValue) throws Exception { meshMQPushConsumer = getMeshMQPushConsumer(); if (meshMQPushConsumer == null) { @@ -88,8 +80,4 @@ public synchronized void shutdown() throws Exception { public void updateOffset(List msgs, AbstractContext eventMeshConsumeConcurrentlyContext) { meshMQPushConsumer.updateOffset(msgs, eventMeshConsumeConcurrentlyContext); } - - public AbstractContext getContext() { - return meshMQPushConsumer.getContext(); - } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerGroupManager.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerGroupManager.java index 76381e322e..93377ac2ea 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerGroupManager.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerGroupManager.java @@ -17,10 +17,14 @@ package org.apache.eventmesh.runtime.core.protocol.http.consumer; +import java.util.Map; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupConf; +import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupTopicConf; public class ConsumerGroupManager { @@ -52,8 +56,8 @@ public synchronized void start() throws Exception { } private synchronized void setupEventMeshConsumer(ConsumerGroupConf consumerGroupConfig) throws Exception { - for (String topic : consumerGroupConfig.getConsumerGroupTopicConf().keySet()) { - eventMeshConsumer.subscribe(topic); + for (Map.Entry conf : consumerGroupConfig.getConsumerGroupTopicConf().entrySet()) { + eventMeshConsumer.subscribe(conf.getKey(), conf.getValue().getSubscriptionItem()); } } @@ -80,4 +84,14 @@ public synchronized void refresh(ConsumerGroupConf consumerGroupConfig) throws E public ConsumerGroupConf getConsumerGroupConfig() { return consumerGroupConfig; } + + public void unsubscribe(String consumerGroup) throws Exception { + if(StringUtils.equals(consumerGroupConfig.getConsumerGroup(), consumerGroup)){ + Set topics = consumerGroupConfig.getConsumerGroupTopicConf().keySet(); + for (String topic : topics){ + ConsumerGroupTopicConf consumerGroupTopicConf = consumerGroupConfig.getConsumerGroupTopicConf().get(topic); + eventMeshConsumer.unsubscribe(topic, consumerGroupTopicConf.getSubscriptionItem().getMode()); + } + } + } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerManager.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerManager.java index 467e4f0cb5..51ede0bdd8 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerManager.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerManager.java @@ -113,6 +113,7 @@ public void run() { ConsumerGroupTopicConf latestTopicConf = new ConsumerGroupTopicConf(); latestTopicConf.setConsumerGroup(consumerGroup); latestTopicConf.setTopic(topic); + latestTopicConf.setSubscriptionItem(map.get(topicKey).getSubscriptionItem()); latestTopicConf.setUrls(clientUrls); latestTopicConf.setIdcUrls(idcUrls); @@ -156,19 +157,19 @@ public void run() { public void notifyConsumerManager(String consumerGroup, ConsumerGroupConf latestConsumerGroupConfig, ConcurrentHashMap localConsumerGroupMapping) throws Exception { ConsumerGroupManager cgm = eventMeshHTTPServer.getConsumerManager().getConsumer(consumerGroup); - if (cgm == null) { + if (latestConsumerGroupConfig == null) { ConsumerGroupStateEvent notification = new ConsumerGroupStateEvent(); - notification.action = ConsumerGroupStateEvent.ConsumerGroupStateAction.NEW; + notification.action = ConsumerGroupStateEvent.ConsumerGroupStateAction.DELETE; notification.consumerGroup = consumerGroup; - notification.consumerGroupConfig = latestConsumerGroupConfig; eventMeshHTTPServer.getEventBus().post(notification); return; } - if (latestConsumerGroupConfig == null) { + if (cgm == null) { ConsumerGroupStateEvent notification = new ConsumerGroupStateEvent(); - notification.action = ConsumerGroupStateEvent.ConsumerGroupStateAction.DELETE; + notification.action = ConsumerGroupStateEvent.ConsumerGroupStateAction.NEW; notification.consumerGroup = consumerGroup; + notification.consumerGroupConfig = latestConsumerGroupConfig; eventMeshHTTPServer.getEventBus().post(notification); return; } @@ -217,8 +218,10 @@ public synchronized void addConsumer(String consumerGroup, ConsumerGroupConf con * restart consumer */ public synchronized void restartConsumer(String consumerGroup, ConsumerGroupConf consumerGroupConfig) throws Exception { - ConsumerGroupManager cgm = consumerTable.get(consumerGroup); - cgm.refresh(consumerGroupConfig); + if(consumerTable.containsKey(consumerGroup)) { + ConsumerGroupManager cgm = consumerTable.get(consumerGroup); + cgm.refresh(consumerGroupConfig); + } } /** @@ -235,8 +238,14 @@ public ConsumerGroupManager getConsumer(String consumerGroup) throws Exception { * @param consumerGroup */ public synchronized void delConsumer(String consumerGroup) throws Exception { - ConsumerGroupManager cgm = consumerTable.remove(consumerGroup); - cgm.shutdown(); + logger.info("start delConsumer with consumerGroup {}", consumerGroup); + if(consumerTable.containsKey(consumerGroup)) { + ConsumerGroupManager cgm = consumerTable.remove(consumerGroup); + logger.info("start unsubscribe topic with consumer group manager {}", JSONObject.toJSONString(cgm)); + cgm.unsubscribe(consumerGroup); + cgm.shutdown(); + } + logger.info("end delConsumer with consumerGroup {}", consumerGroup); } @Subscribe diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/EventMeshConsumer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/EventMeshConsumer.java index 186ca35c35..8620e682ab 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/EventMeshConsumer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/EventMeshConsumer.java @@ -21,7 +21,6 @@ import java.util.Properties; import java.util.concurrent.atomic.AtomicBoolean; -import io.openmessaging.api.Action; import io.openmessaging.api.AsyncConsumeContext; import io.openmessaging.api.AsyncMessageListener; import io.openmessaging.api.Message; @@ -31,7 +30,11 @@ import org.apache.commons.collections4.MapUtils; import org.apache.eventmesh.api.AbstractContext; +import org.apache.eventmesh.api.EventMeshAction; +import org.apache.eventmesh.api.EventMeshAsyncConsumeContext; import org.apache.eventmesh.common.Constants; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupConf; @@ -81,7 +84,6 @@ public synchronized void init() throws Exception { keyValue.put("consumerGroup", consumerGroupConf.getConsumerGroup()); keyValue.put("eventMeshIDC", eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); keyValue.put("instanceName", EventMeshUtil.buildMeshClientID(consumerGroupConf.getConsumerGroup(), - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshRegion, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster)); persistentMqConsumer.init(keyValue); @@ -91,7 +93,6 @@ public synchronized void init() throws Exception { broadcastKeyValue.put("consumerGroup", consumerGroupConf.getConsumerGroup()); broadcastKeyValue.put("eventMeshIDC", eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); broadcastKeyValue.put("instanceName", EventMeshUtil.buildMeshClientID(consumerGroupConf.getConsumerGroup(), - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshRegion, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster)); broadcastMqConsumer.init(broadcastKeyValue); inited4Persistent.compareAndSet(false, true); @@ -100,16 +101,15 @@ public synchronized void init() throws Exception { } public synchronized void start() throws Exception { - persistentMqConsumer.start(); started4Persistent.compareAndSet(false, true); broadcastMqConsumer.start(); started4Broadcast.compareAndSet(false, true); } - public void subscribe(String topic) throws Exception { + public void subscribe(String topic, SubscriptionItem subscriptionItem) throws Exception { AsyncMessageListener listener = null; - if (!EventMeshUtil.isBroadcast(topic)) { + if (!SubscriptionMode.BROADCASTING.equals(subscriptionItem.getMode())) { listener = new AsyncMessageListener() { @Override public void consume(Message message, AsyncConsumeContext context) { @@ -125,6 +125,7 @@ public void consume(Message message, AsyncConsumeContext context) { } ConsumerGroupTopicConf currentTopicConfig = MapUtils.getObject(consumerGroupConf.getConsumerGroupTopicConf(), topic, null); + EventMeshAsyncConsumeContext eventMeshAsyncConsumeContext = (EventMeshAsyncConsumeContext)context; if (currentTopicConfig == null) { logger.error("no topicConfig found, consumerGroup:{} topic:{}", consumerGroupConf.getConsumerGroup(), topic); @@ -132,18 +133,18 @@ public void consume(Message message, AsyncConsumeContext context) { sendMessageBack(message, uniqueId, bizSeqNo); // context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); // context.ack(); - context.commit(Action.CommitMessage); + eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage); return; } catch (Exception ex) { } } HandleMsgContext handleMsgContext = new HandleMsgContext(EventMeshUtil.buildPushMsgSeqNo(), consumerGroupConf.getConsumerGroup(), EventMeshConsumer.this, - topic, message, persistentMqConsumer.getContext(), consumerGroupConf, eventMeshHTTPServer, bizSeqNo, uniqueId, currentTopicConfig); + topic, message, subscriptionItem, eventMeshAsyncConsumeContext.getAbstractContext(), consumerGroupConf, eventMeshHTTPServer, bizSeqNo, uniqueId, currentTopicConfig); if (httpMessageHandler.handle(handleMsgContext)) { // context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); // context.ack(); - context.commit(Action.CommitMessage); + eventMeshAsyncConsumeContext.commit(EventMeshAction.ManualAck); } else { try { sendMessageBack(message, uniqueId, bizSeqNo); @@ -152,7 +153,7 @@ public void consume(Message message, AsyncConsumeContext context) { } // context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); // context.ack(); - context.commit(Action.CommitMessage); + eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage); } } }; @@ -174,6 +175,7 @@ public void consume(Message message, AsyncConsumeContext context) { } ConsumerGroupTopicConf currentTopicConfig = MapUtils.getObject(consumerGroupConf.getConsumerGroupTopicConf(), topic, null); + EventMeshAsyncConsumeContext eventMeshAsyncConsumeContext = (EventMeshAsyncConsumeContext)context; if (currentTopicConfig == null) { logger.error("no topicConfig found, consumerGroup:{} topic:{}", consumerGroupConf.getConsumerGroup(), topic); @@ -181,18 +183,18 @@ public void consume(Message message, AsyncConsumeContext context) { sendMessageBack(message, uniqueId, bizSeqNo); // context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); // context.ack(); - context.commit(Action.CommitMessage); + eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage); return; } catch (Exception ex) { } } HandleMsgContext handleMsgContext = new HandleMsgContext(EventMeshUtil.buildPushMsgSeqNo(), consumerGroupConf.getConsumerGroup(), EventMeshConsumer.this, - topic, message, broadcastMqConsumer.getContext(), consumerGroupConf, eventMeshHTTPServer, bizSeqNo, uniqueId, currentTopicConfig); + topic, message, subscriptionItem, eventMeshAsyncConsumeContext.getAbstractContext(), consumerGroupConf, eventMeshHTTPServer, bizSeqNo, uniqueId, currentTopicConfig); if (httpMessageHandler.handle(handleMsgContext)) { // context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); // context.ack(); - context.commit(Action.CommitMessage); + eventMeshAsyncConsumeContext.commit(EventMeshAction.ManualAck); } else { try { sendMessageBack(message, uniqueId, bizSeqNo); @@ -201,7 +203,7 @@ public void consume(Message message, AsyncConsumeContext context) { } // context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); // context.ack(); - context.commit(Action.CommitMessage); + eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage); } } }; @@ -209,8 +211,8 @@ public void consume(Message message, AsyncConsumeContext context) { } } - public void unsubscribe(String topic) throws Exception { - if (EventMeshUtil.isBroadcast(topic)) { + public void unsubscribe(String topic, SubscriptionMode subscriptionMode) throws Exception { + if (SubscriptionMode.BROADCASTING.equals(subscriptionMode)) { broadcastMqConsumer.unsubscribe(topic); } else { persistentMqConsumer.unsubscribe(topic); @@ -233,8 +235,8 @@ public synchronized void shutdown() throws Exception { started4Broadcast.compareAndSet(true, false); } - public void updateOffset(String topic, List msgs, AbstractContext context) { - if (EventMeshUtil.isBroadcast(topic)) { + public void updateOffset(String topic, SubscriptionMode subscriptionMode, List msgs, AbstractContext context) { + if (SubscriptionMode.BROADCASTING.equals(subscriptionMode)) { broadcastMqConsumer.updateOffset(msgs, context); } else { persistentMqConsumer.updateOffset(msgs, context); @@ -252,8 +254,7 @@ public EventMeshHTTPServer getEventMeshHTTPServer() { public void sendMessageBack(final Message msgBack, final String uniqueId, String bizSeqNo) throws Exception { EventMeshProducer sendMessageBack - = eventMeshHTTPServer.getProducerManager().getEventMeshProducer(EventMeshConstants.PRODUCER_GROUP_NAME_PREFIX - + consumerGroupConf.getConsumerGroup()); + = eventMeshHTTPServer.getProducerManager().getEventMeshProducer(consumerGroupConf.getConsumerGroup()); if (sendMessageBack == null) { logger.warn("consumer:{} consume fail, sendMessageBack, bizSeqNo:{}, uniqueId:{}", consumerGroupConf.getConsumerGroup(), bizSeqNo, uniqueId); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/HandleMsgContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/HandleMsgContext.java index afb27c1515..2d19174b11 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/HandleMsgContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/HandleMsgContext.java @@ -23,10 +23,14 @@ import io.openmessaging.api.Message; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.api.AbstractContext; import org.apache.eventmesh.common.Constants; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupConf; import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupTopicConf; import org.slf4j.Logger; @@ -48,6 +52,8 @@ public class HandleMsgContext { private String topic; + private SubscriptionItem subscriptionItem; + private Message msg; private int ttl; @@ -65,7 +71,7 @@ public class HandleMsgContext { private Map props; public HandleMsgContext(String msgRandomNo, String consumerGroup, EventMeshConsumer eventMeshConsumer, - String topic, Message msg, + String topic, Message msg, SubscriptionItem subscriptionItem, AbstractContext context, ConsumerGroupConf consumerGroupConfig, EventMeshHTTPServer eventMeshHTTPServer, String bizSeqNo, String uniqueId, ConsumerGroupTopicConf consumeTopicConfig) { this.msgRandomNo = msgRandomNo; @@ -73,13 +79,15 @@ public HandleMsgContext(String msgRandomNo, String consumerGroup, EventMeshConsu this.eventMeshConsumer = eventMeshConsumer; this.topic = topic; this.msg = msg; + this.subscriptionItem = subscriptionItem; this.context = context; this.consumerGroupConfig = consumerGroupConfig; this.eventMeshHTTPServer = eventMeshHTTPServer; this.bizSeqNo = bizSeqNo; this.uniqueId = uniqueId; this.consumeTopicConfig = consumeTopicConfig; - this.ttl = Integer.parseInt(msg.getUserProperties(Constants.PROPERTY_MESSAGE_TIMEOUT)); + String ttlStr = msg.getUserProperties(Constants.PROPERTY_MESSAGE_TIMEOUT); + this.ttl = StringUtils.isNumeric(ttlStr)? Integer.parseInt(ttlStr): EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; } public void addProp(String key, String val) { @@ -149,6 +157,14 @@ public void setMsg(Message msg) { this.msg = msg; } + public SubscriptionItem getSubscriptionItem() { + return subscriptionItem; + } + + public void setSubscriptionItem(SubscriptionItem subscriptionItem) { + this.subscriptionItem = subscriptionItem; + } + public long getCreateTime() { return createTime; } @@ -185,7 +201,7 @@ public void finish() { // msg.getProperty(DeFiBusConstant.PROPERTY_MESSAGE_BROKER), // msg.getQueueId(), msg.getQueueOffset()); } - eventMeshConsumer.updateOffset(topic, Arrays.asList(msg), context); + eventMeshConsumer.updateOffset(topic, subscriptionItem.getMode(), Arrays.asList(msg), context); } } @@ -211,6 +227,7 @@ public String toString() { sb.append("handleMsgContext={") .append("consumerGroup=").append(consumerGroup) .append(",topic=").append(topic) + .append(",subscriptionItem=").append(subscriptionItem) .append(",consumeTopicConfig=").append(consumeTopicConfig) .append(",bizSeqNo=").append(bizSeqNo) .append(",uniqueId=").append(uniqueId) diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageProcessor.java index 37d28b7d69..df3b2afcd5 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageProcessor.java @@ -78,8 +78,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext SendMessageBatchResponseHeader sendMessageBatchResponseHeader = SendMessageBatchResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, IPUtil.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshRegion, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshDCN, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); if (StringUtils.isBlank(sendMessageBatchRequestHeader.getPid()) || !StringUtils.isNumeric(sendMessageBatchRequestHeader.getPid()) @@ -93,6 +92,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext if (CollectionUtils.isEmpty(sendMessageBatchRequestBody.getContents()) || StringUtils.isBlank(sendMessageBatchRequestBody.getBatchId()) + || StringUtils.isBlank(sendMessageBatchRequestBody.getProducerGroup()) || (Integer.valueOf(sendMessageBatchRequestBody.getSize()) != CollectionUtils.size(sendMessageBatchRequestBody.getContents()))) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageBatchResponseHeader, @@ -112,11 +112,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext return; } - if (StringUtils.isBlank(sendMessageBatchRequestHeader.getDcn())) { - sendMessageBatchRequestHeader.setDcn("BATCH"); - } - String producerGroup = EventMeshUtil.buildClientGroup(sendMessageBatchRequestHeader.getSys(), - sendMessageBatchRequestHeader.getDcn()); + + String producerGroup = sendMessageBatchRequestBody.getProducerGroup(); EventMeshProducer batchEventMeshProducer = eventMeshHTTPServer.getProducerManager().getEventMeshProducer(producerGroup); batchEventMeshProducer.getMqProducerWrapper().getMeshMQProducer().setExtFields(); @@ -188,7 +185,9 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext return; } - eventMeshHTTPServer.metrics.summaryMetrics.recordSendBatchMsg(Integer.parseInt(sendMessageBatchRequestBody.getSize())); + String sizeStr = sendMessageBatchRequestBody.getSize(); + long delta = StringUtils.isNumeric(sizeStr)? Integer.parseInt(sizeStr) : 0; + eventMeshHTTPServer.metrics.summaryMetrics.recordSendBatchMsg(delta); if (eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshServerBatchMsgBatchEnabled) { for (List batchMsgs : topicBatchMessageMappings.values()) { diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageV2Processor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageV2Processor.java index 5dff4082cd..8d5f7b5b92 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageV2Processor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageV2Processor.java @@ -73,8 +73,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext SendMessageBatchV2ResponseHeader sendMessageBatchV2ResponseHeader = SendMessageBatchV2ResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, IPUtil.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshRegion, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshDCN, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); if (StringUtils.isBlank(sendMessageBatchV2RequestHeader.getPid()) || !StringUtils.isNumeric(sendMessageBatchV2RequestHeader.getPid()) @@ -88,6 +87,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext if (StringUtils.isBlank(sendMessageBatchV2RequestBody.getBizSeqNo()) || StringUtils.isBlank(sendMessageBatchV2RequestBody.getTopic()) + || StringUtils.isBlank(sendMessageBatchV2RequestBody.getProducerGroup()) || StringUtils.isBlank(sendMessageBatchV2RequestBody.getMsg())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageBatchV2ResponseHeader, @@ -107,11 +107,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext return; } - if (StringUtils.isBlank(sendMessageBatchV2RequestHeader.getDcn())) { - sendMessageBatchV2RequestHeader.setDcn("BATCH"); - } - String producerGroup = EventMeshUtil.buildClientGroup(sendMessageBatchV2RequestHeader.getSys(), - sendMessageBatchV2RequestHeader.getDcn()); + String producerGroup = sendMessageBatchV2RequestBody.getProducerGroup(); EventMeshProducer batchEventMeshProducer = eventMeshHTTPServer.getProducerManager().getEventMeshProducer(producerGroup); batchEventMeshProducer.getMqProducerWrapper().getMeshMQProducer().setExtFields(); // batchEventMeshProducer.getMqProducerWrapper().getDefaultMQProducer().setRetryTimesWhenSendAsyncFailed(0); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HeartBeatProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HeartBeatProcessor.java index febfa91f48..9e4c41eda3 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HeartBeatProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HeartBeatProcessor.java @@ -68,13 +68,11 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext HeartbeatResponseHeader heartbeatResponseHeader = HeartbeatResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, IPUtil.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshRegion, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshDCN, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); //validate header if (StringUtils.isBlank(heartbeatRequestHeader.getIdc()) - || StringUtils.isBlank(heartbeatRequestHeader.getDcn()) || StringUtils.isBlank(heartbeatRequestHeader.getPid()) || !StringUtils.isNumeric(heartbeatRequestHeader.getPid()) || StringUtils.isBlank(heartbeatRequestHeader.getSys())) { @@ -87,6 +85,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext //validate body if (StringUtils.isBlank(heartbeatRequestBody.getClientType()) + || StringUtils.isBlank(heartbeatRequestBody.getConsumerGroup()) || CollectionUtils.isEmpty(heartbeatRequestBody.getHeartbeatEntities())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( @@ -97,20 +96,17 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext } ConcurrentHashMap> tmp = new ConcurrentHashMap<>(); String env = heartbeatRequestHeader.getEnv(); - String dcn = heartbeatRequestHeader.getDcn(); String idc = heartbeatRequestHeader.getIdc(); String sys = heartbeatRequestHeader.getSys(); String ip = heartbeatRequestHeader.getIp(); String pid = heartbeatRequestHeader.getPid(); - String consumerGroup = EventMeshUtil.buildClientGroup(heartbeatRequestHeader.getSys(), - heartbeatRequestHeader.getDcn()); + String consumerGroup = heartbeatRequestBody.getConsumerGroup(); List heartbeatEntities = heartbeatRequestBody.getHeartbeatEntities(); for (HeartbeatRequestBody.HeartbeatEntity heartbeatEntity : heartbeatEntities) { String topic = heartbeatEntity.topic; String url = heartbeatEntity.url; Client client = new Client(); client.env = env; - client.dcn = dcn; client.idc = idc; client.sys = sys; client.ip = ip; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/ReplyMessageProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/ReplyMessageProcessor.java index 3c461edbb2..5d8745b611 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/ReplyMessageProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/ReplyMessageProcessor.java @@ -78,12 +78,10 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext ReplyMessageResponseHeader replyMessageResponseHeader = ReplyMessageResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, IPUtil.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshRegion, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshDCN, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); //HEADER校验 if (StringUtils.isBlank(replyMessageRequestHeader.getIdc()) - || StringUtils.isBlank(replyMessageRequestHeader.getDcn()) || StringUtils.isBlank(replyMessageRequestHeader.getPid()) || !StringUtils.isNumeric(replyMessageRequestHeader.getPid()) || StringUtils.isBlank(replyMessageRequestHeader.getSys())) { @@ -97,6 +95,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext //validate body if (StringUtils.isBlank(replyMessageRequestBody.getBizSeqNo()) || StringUtils.isBlank(replyMessageRequestBody.getUniqueId()) + || StringUtils.isBlank(replyMessageRequestBody.getProducerGroup()) || StringUtils.isBlank(replyMessageRequestBody.getContent())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( replyMessageResponseHeader, @@ -105,8 +104,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext return; } - String producerGroup = EventMeshUtil.buildClientGroup(replyMessageRequestHeader.getSys(), - replyMessageRequestHeader.getDcn()); + String producerGroup = replyMessageRequestBody.getProducerGroup(); EventMeshProducer eventMeshProducer = eventMeshHTTPServer.getProducerManager().getEventMeshProducer(producerGroup); if (!eventMeshProducer.getStarted().get()) { diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendAsyncMessageProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendAsyncMessageProcessor.java index 8fd2fad76d..cd3d4bed35 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendAsyncMessageProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendAsyncMessageProcessor.java @@ -75,12 +75,10 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext SendMessageResponseHeader sendMessageResponseHeader = SendMessageResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, IPUtil.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshRegion, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshDCN, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); //validate header if (StringUtils.isBlank(sendMessageRequestHeader.getIdc()) - || StringUtils.isBlank(sendMessageRequestHeader.getDcn()) || StringUtils.isBlank(sendMessageRequestHeader.getPid()) || !StringUtils.isNumeric(sendMessageRequestHeader.getPid()) || StringUtils.isBlank(sendMessageRequestHeader.getSys())) { @@ -94,6 +92,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext //validate body if (StringUtils.isBlank(sendMessageRequestBody.getBizSeqNo()) || StringUtils.isBlank(sendMessageRequestBody.getUniqueId()) + || StringUtils.isBlank(sendMessageRequestBody.getProducerGroup()) || StringUtils.isBlank(sendMessageRequestBody.getTopic()) || StringUtils.isBlank(sendMessageRequestBody.getContent()) || (StringUtils.isBlank(sendMessageRequestBody.getTtl()))) { @@ -105,8 +104,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext return; } - String producerGroup = EventMeshUtil.buildClientGroup(sendMessageRequestHeader.getSys(), - sendMessageRequestHeader.getDcn()); + String producerGroup = sendMessageRequestBody.getProducerGroup(); EventMeshProducer eventMeshProducer = eventMeshHTTPServer.getProducerManager().getEventMeshProducer(producerGroup); if (!eventMeshProducer.getStarted().get()) { diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendSyncMessageProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendSyncMessageProcessor.java index d2dacdb552..5511e384e3 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendSyncMessageProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendSyncMessageProcessor.java @@ -79,11 +79,9 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext SendMessageResponseHeader sendMessageResponseHeader = SendMessageResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, IPUtil.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshRegion, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshDCN, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); if (StringUtils.isBlank(sendMessageRequestHeader.getIdc()) - || StringUtils.isBlank(sendMessageRequestHeader.getDcn()) || StringUtils.isBlank(sendMessageRequestHeader.getPid()) || !StringUtils.isNumeric(sendMessageRequestHeader.getPid()) || StringUtils.isBlank(sendMessageRequestHeader.getSys())) { @@ -96,6 +94,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext if (StringUtils.isBlank(sendMessageRequestBody.getBizSeqNo()) || StringUtils.isBlank(sendMessageRequestBody.getUniqueId()) + || StringUtils.isBlank(sendMessageRequestBody.getProducerGroup()) || StringUtils.isBlank(sendMessageRequestBody.getTopic()) || StringUtils.isBlank(sendMessageRequestBody.getContent()) || (StringUtils.isBlank(sendMessageRequestBody.getTtl()))) { @@ -106,8 +105,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext return; } - String producerGroup = EventMeshUtil.buildClientGroup(sendMessageRequestHeader.getSys(), - sendMessageRequestHeader.getDcn()); + String producerGroup = sendMessageRequestBody.getProducerGroup(); EventMeshProducer eventMeshProducer = eventMeshHTTPServer.getProducerManager().getEventMeshProducer(producerGroup); if (!eventMeshProducer.getStarted().get()) { @@ -140,7 +138,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext omsMsg.putUserProperties("msgType", "persistent"); omsMsg.putUserProperties(EventMeshConstants.REQ_C2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())); omsMsg.putUserProperties(Constants.RMB_UNIQ_ID, sendMessageRequestBody.getUniqueId()); - omsMsg.putUserProperties("REPLY_TO", eventMeshProducer.getMqProducerWrapper().getMeshMQProducer().buildMQClientId()); +// omsMsg.putUserProperties("REPLY_TO", eventMeshProducer.getMqProducerWrapper().getMeshMQProducer().buildMQClientId()); if (messageLogger.isDebugEnabled()) { messageLogger.debug("msg2MQMsg suc, bizSeqNo={}, topic={}", sendMessageRequestBody.getBizSeqNo(), diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SubscribeProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SubscribeProcessor.java index 54fa73edde..e22a86c7c1 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SubscribeProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SubscribeProcessor.java @@ -19,19 +19,18 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; - import com.alibaba.fastjson.JSONObject; - import io.netty.channel.ChannelHandlerContext; - import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.IPUtil; import org.apache.eventmesh.common.command.HttpCommand; +import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.http.body.client.SubscribeRequestBody; import org.apache.eventmesh.common.protocol.http.body.client.SubscribeResponseBody; import org.apache.eventmesh.common.protocol.http.common.EventMeshRetCode; @@ -73,13 +72,11 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext SubscribeResponseHeader subscribeResponseHeader = SubscribeResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, IPUtil.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshRegion, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshDCN, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); //validate header if (StringUtils.isBlank(subscribeRequestHeader.getIdc()) - || StringUtils.isBlank(subscribeRequestHeader.getDcn()) || StringUtils.isBlank(subscribeRequestHeader.getPid()) || !StringUtils.isNumeric(subscribeRequestHeader.getPid()) || StringUtils.isBlank(subscribeRequestHeader.getSys())) { @@ -92,7 +89,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext //validate body if (StringUtils.isBlank(subscribeRequestBody.getUrl()) - || CollectionUtils.isEmpty(subscribeRequestBody.getTopics())) { + || CollectionUtils.isEmpty(subscribeRequestBody.getTopics()) + || StringUtils.isBlank(subscribeRequestBody.getConsumerGroup())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( subscribeResponseHeader, @@ -100,17 +98,17 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext asyncContext.onComplete(responseEventMeshCommand); return; } - List subTopicList = subscribeRequestBody.getTopics(); + List subTopicList = subscribeRequestBody.getTopics(); String url = subscribeRequestBody.getUrl(); - String consumerGroup = EventMeshUtil.buildClientGroup(subscribeRequestHeader.getSys(), - subscribeRequestHeader.getDcn()); + String consumerGroup = subscribeRequestBody.getConsumerGroup(); synchronized (eventMeshHTTPServer.localClientInfoMapping) { + registerClient(subscribeRequestHeader, consumerGroup, subTopicList, url); - for (String subTopic : subTopicList) { - List groupTopicClients = eventMeshHTTPServer.localClientInfoMapping.get(consumerGroup + "@" + subTopic); + for (SubscriptionItem subTopic : subTopicList) { + List groupTopicClients = eventMeshHTTPServer.localClientInfoMapping.get(consumerGroup + "@" + subTopic.getTopic()); if (CollectionUtils.isEmpty(groupTopicClients)) { httpLogger.error("group {} topic {} clients is empty", consumerGroup, subTopic); @@ -132,23 +130,25 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext consumerGroupConf = new ConsumerGroupConf(consumerGroup); ConsumerGroupTopicConf consumeTopicConfig = new ConsumerGroupTopicConf(); consumeTopicConfig.setConsumerGroup(consumerGroup); - consumeTopicConfig.setTopic(subTopic); + consumeTopicConfig.setTopic(subTopic.getTopic()); + consumeTopicConfig.setSubscriptionItem(subTopic); consumeTopicConfig.setUrls(new HashSet<>(Arrays.asList(url))); consumeTopicConfig.setIdcUrls(idcUrls); Map map = new HashMap<>(); - map.put(subTopic, consumeTopicConfig); + map.put(subTopic.getTopic(), consumeTopicConfig); consumerGroupConf.setConsumerGroupTopicConf(map); } else { // 已有订阅 Map map = consumerGroupConf.getConsumerGroupTopicConf(); for (String key : map.keySet()) { - if (StringUtils.equals(subTopic, key)) { + if (StringUtils.equals(subTopic.getTopic(), key)) { ConsumerGroupTopicConf latestTopicConf = new ConsumerGroupTopicConf(); ConsumerGroupTopicConf currentTopicConf = map.get(key); latestTopicConf.setConsumerGroup(consumerGroup); - latestTopicConf.setTopic(subTopic); + latestTopicConf.setTopic(subTopic.getTopic()); + latestTopicConf.setSubscriptionItem(subTopic); latestTopicConf.setUrls(new HashSet<>(Arrays.asList(url))); latestTopicConf.getUrls().addAll(currentTopicConf.getUrls()); @@ -206,4 +206,40 @@ public boolean rejectRequest() { return false; } + private void registerClient(SubscribeRequestHeader subscribeRequestHeader, String consumerGroup, + List subscriptionItems, String url) { + for(SubscriptionItem item: subscriptionItems) { + Client client = new Client(); + client.env = subscribeRequestHeader.getEnv(); + client.idc = subscribeRequestHeader.getIdc(); + client.sys = subscribeRequestHeader.getSys(); + client.ip = subscribeRequestHeader.getIp(); + client.pid = subscribeRequestHeader.getPid(); + client.consumerGroup = consumerGroup; + client.topic = item.getTopic(); + client.url = url; + client.lastUpTime = new Date(); + + String groupTopicKey = client.consumerGroup + "@" + client.topic; + + if (eventMeshHTTPServer.localClientInfoMapping.containsKey(groupTopicKey)) { + List localClients = eventMeshHTTPServer.localClientInfoMapping.get(groupTopicKey); + boolean isContains = false; + for (Client localClient : localClients) { + if (StringUtils.equals(localClient.url, client.url)) { + isContains = true; + localClient.lastUpTime = client.lastUpTime; + break; + } + } + if (!isContains) { + localClients.add(client); + } + } else { + List clients = new ArrayList<>(); + clients.add(client); + eventMeshHTTPServer.localClientInfoMapping.put(groupTopicKey, clients); + } + } + } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/UnSubscribeProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/UnSubscribeProcessor.java index 67ab9fd702..d45781293b 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/UnSubscribeProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/UnSubscribeProcessor.java @@ -18,18 +18,15 @@ package org.apache.eventmesh.runtime.core.protocol.http.processor; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - import com.alibaba.fastjson.JSONObject; - import io.netty.channel.ChannelHandlerContext; - import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.IPUtil; @@ -44,10 +41,8 @@ import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupConf; import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupTopicConf; -import org.apache.eventmesh.runtime.core.consumergroup.event.ConsumerGroupStateEvent; import org.apache.eventmesh.runtime.core.protocol.http.async.AsyncContext; import org.apache.eventmesh.runtime.core.protocol.http.async.CompleteHandler; -import org.apache.eventmesh.runtime.core.protocol.http.consumer.ConsumerGroupManager; import org.apache.eventmesh.runtime.core.protocol.http.processor.inf.Client; import org.apache.eventmesh.runtime.core.protocol.http.processor.inf.HttpRequestProcessor; import org.apache.eventmesh.runtime.util.EventMeshUtil; @@ -77,13 +72,11 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext UnSubscribeResponseHeader unSubscribeResponseHeader = UnSubscribeResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, IPUtil.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshRegion, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshDCN, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); //validate header if (StringUtils.isBlank(unSubscribeRequestHeader.getIdc()) - || StringUtils.isBlank(unSubscribeRequestHeader.getDcn()) || StringUtils.isBlank(unSubscribeRequestHeader.getPid()) || !StringUtils.isNumeric(unSubscribeRequestHeader.getPid()) || StringUtils.isBlank(unSubscribeRequestHeader.getSys())) { @@ -96,7 +89,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext //validate body if (StringUtils.isBlank(unSubscribeRequestBody.getUrl()) - || CollectionUtils.isEmpty(unSubscribeRequestBody.getTopics())) { + || CollectionUtils.isEmpty(unSubscribeRequestBody.getTopics()) + || StringUtils.isBlank(unSubscribeRequestBody.getConsumerGroup())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( unSubscribeResponseHeader, @@ -105,13 +99,11 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext return; } String env = unSubscribeRequestHeader.getEnv(); - String dcn = unSubscribeRequestHeader.getDcn(); String idc = unSubscribeRequestHeader.getIdc(); String sys = unSubscribeRequestHeader.getSys(); String ip = unSubscribeRequestHeader.getIp(); String pid = unSubscribeRequestHeader.getPid(); - String consumerGroup = EventMeshUtil.buildClientGroup(unSubscribeRequestHeader.getSys(), - unSubscribeRequestHeader.getDcn()); + String consumerGroup = unSubscribeRequestBody.getConsumerGroup(); String unSubscribeUrl = unSubscribeRequestBody.getUrl(); List unSubTopicList = unSubscribeRequestBody.getTopics(); @@ -131,12 +123,15 @@ public void onResponse(HttpCommand httpCommand) { synchronized (eventMeshHTTPServer.localClientInfoMapping) { boolean isChange = true; + + registerClient(unSubscribeRequestHeader, consumerGroup, unSubTopicList, unSubscribeUrl); + for (String unSubTopic : unSubTopicList) { List groupTopicClients = eventMeshHTTPServer.localClientInfoMapping.get(consumerGroup + "@" + unSubTopic); Iterator clientIterator = groupTopicClients.iterator(); while (clientIterator.hasNext()) { Client client = clientIterator.next(); - if (StringUtils.equals(client.ip, ip)) { + if (StringUtils.equals(client.pid, pid) && StringUtils.equals(client.url, unSubscribeUrl)) { httpLogger.warn("client {} start unsubscribe", JSONObject.toJSONString(client)); clientIterator.remove(); } @@ -168,6 +163,7 @@ public void onResponse(HttpCommand httpCommand) { ConsumerGroupTopicConf latestTopicConf = new ConsumerGroupTopicConf(); latestTopicConf.setConsumerGroup(consumerGroup); latestTopicConf.setTopic(unSubTopic); + latestTopicConf.setSubscriptionItem(map.get(topicKey).getSubscriptionItem()); latestTopicConf.setUrls(clientUrls); latestTopicConf.setIdcUrls(idcUrls); @@ -240,36 +236,39 @@ public boolean rejectRequest() { return false; } - /** - * notify ConsumerManager 组级别 - */ - private void notifyConsumerManager(String consumerGroup, ConsumerGroupConf latestConsumerGroupConfig, - ConcurrentHashMap localConsumerGroupMapping) throws Exception { - ConsumerGroupManager cgm = eventMeshHTTPServer.getConsumerManager().getConsumer(consumerGroup); - if (cgm == null) { - ConsumerGroupStateEvent notification = new ConsumerGroupStateEvent(); - notification.action = ConsumerGroupStateEvent.ConsumerGroupStateAction.NEW; - notification.consumerGroup = consumerGroup; - notification.consumerGroupConfig = latestConsumerGroupConfig; - eventMeshHTTPServer.getEventBus().post(notification); - return; - } + private void registerClient(UnSubscribeRequestHeader unSubscribeRequestHeader, String consumerGroup, + List topicList, String url) { + for(String topic: topicList) { + Client client = new Client(); + client.env = unSubscribeRequestHeader.getEnv(); + client.idc = unSubscribeRequestHeader.getIdc(); + client.sys = unSubscribeRequestHeader.getSys(); + client.ip = unSubscribeRequestHeader.getIp(); + client.pid = unSubscribeRequestHeader.getPid(); + client.consumerGroup = consumerGroup; + client.topic = topic; + client.url = url; + client.lastUpTime = new Date(); - if (!latestConsumerGroupConfig.equals(cgm.getConsumerGroupConfig())) { - ConsumerGroupStateEvent notification = new ConsumerGroupStateEvent(); - notification.action = ConsumerGroupStateEvent.ConsumerGroupStateAction.CHANGE; - notification.consumerGroup = consumerGroup; - notification.consumerGroupConfig = latestConsumerGroupConfig; - eventMeshHTTPServer.getEventBus().post(notification); - return; - } - - if (latestConsumerGroupConfig == null) { - ConsumerGroupStateEvent notification = new ConsumerGroupStateEvent(); - notification.action = ConsumerGroupStateEvent.ConsumerGroupStateAction.DELETE; - notification.consumerGroup = consumerGroup; - eventMeshHTTPServer.getEventBus().post(notification); + String groupTopicKey = client.consumerGroup + "@" + client.topic; + if (eventMeshHTTPServer.localClientInfoMapping.containsKey(groupTopicKey)) { + List localClients = eventMeshHTTPServer.localClientInfoMapping.get(groupTopicKey); + boolean isContains = false; + for (Client localClient : localClients) { + if (StringUtils.equals(localClient.url, client.url)) { + isContains = true; + localClient.lastUpTime = client.lastUpTime; + break; + } + } + if (!isContains) { + localClients.add(client); + } + } else { + List clients = new ArrayList<>(); + clients.add(client); + eventMeshHTTPServer.localClientInfoMapping.put(groupTopicKey, clients); + } } - return; } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/inf/Client.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/inf/Client.java index 4387509e10..1b834d90d7 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/inf/Client.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/inf/Client.java @@ -28,8 +28,6 @@ public class Client { public String env; - public String dcn; - public String idc; public String consumerGroup; @@ -64,7 +62,6 @@ public static Client buildClientFromJSONObject(JSONObject jsonObject) { client.topic = StringUtils.trim(jsonObject.getString("topic")); client.url = StringUtils.trim(jsonObject.getString("url")); client.sys = StringUtils.trim(jsonObject.getString("sys")); - client.dcn = StringUtils.trim(jsonObject.getString("dcn")); client.idc = StringUtils.trim(jsonObject.getString("idc")); client.ip = StringUtils.trim(jsonObject.getString("ip")); client.pid = StringUtils.trim(jsonObject.getString("pid")); @@ -79,7 +76,6 @@ public static Client buildClientFromJSONObject(JSONObject jsonObject) { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("endPoint={env=").append(env) - .append(",dcn=").append(dcn) .append(",idc=").append(idc) .append(",consumerGroup=").append(consumerGroup) .append(",topic=").append(topic) diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/EventMeshProducer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/EventMeshProducer.java index c5806daddf..cf41ca2b9e 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/EventMeshProducer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/EventMeshProducer.java @@ -81,8 +81,7 @@ public synchronized void init(EventMeshHTTPConfiguration eventMeshHttpConfigurat Properties keyValue = new Properties(); keyValue.put("producerGroup", producerGroupConfig.getGroupName()); - keyValue.put("instanceName", EventMeshUtil.buildMeshClientID(producerGroupConfig.getGroupName(), - eventMeshHttpConfiguration.eventMeshRegion, eventMeshHttpConfiguration.eventMeshCluster)); + keyValue.put("instanceName", EventMeshUtil.buildMeshClientID(producerGroupConfig.getGroupName(), eventMeshHttpConfiguration.eventMeshCluster)); //TODO for defibus keyValue.put("eventMeshIDC", eventMeshHttpConfiguration.eventMeshIDC); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AsyncHTTPPushRequest.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AsyncHTTPPushRequest.java index af71ce837b..3ab5649b89 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AsyncHTTPPushRequest.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AsyncHTTPPushRequest.java @@ -35,6 +35,7 @@ import org.apache.commons.text.RandomStringGenerator; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.IPUtil; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.http.body.message.PushMessageRequestBody; import org.apache.eventmesh.common.protocol.http.common.ClientRetCode; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; @@ -88,7 +89,7 @@ public void tryHTTPRequest() { String requestCode = ""; - if (EventMeshUtil.isService(handleMsgContext.getTopic())) { + if (SubcriptionType.SYNC.equals(handleMsgContext.getSubscriptionItem().getType())) { requestCode = String.valueOf(RequestCode.HTTP_PUSH_CLIENT_SYNC.getRequestCode()); } else { requestCode = String.valueOf(RequestCode.HTTP_PUSH_CLIENT_ASYNC.getRequestCode()); @@ -99,9 +100,7 @@ public void tryHTTPRequest() { builder.addHeader(ProtocolKey.VERSION, ProtocolVersion.V1.getVersion()); builder.addHeader(ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER, handleMsgContext.getEventMeshHTTPServer().getEventMeshHttpConfiguration().eventMeshCluster); builder.addHeader(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, IPUtil.getLocalAddress()); - builder.addHeader(ProtocolKey.EventMeshInstanceKey.EVENTMESHDCN, handleMsgContext.getEventMeshHTTPServer().getEventMeshHttpConfiguration().eventMeshDCN); builder.addHeader(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, handleMsgContext.getEventMeshHTTPServer().getEventMeshHttpConfiguration().eventMeshEnv); - builder.addHeader(ProtocolKey.EventMeshInstanceKey.EVENTMESHREGION, handleMsgContext.getEventMeshHTTPServer().getEventMeshHttpConfiguration().eventMeshRegion); builder.addHeader(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, handleMsgContext.getEventMeshHTTPServer().getEventMeshHttpConfiguration().eventMeshIDC); handleMsgContext.getMsg().getUserProperties().put(EventMeshConstants.REQ_EVENTMESH2C_TIMESTAMP, String.valueOf(System.currentTimeMillis())); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientGroupWrapper.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientGroupWrapper.java index 35e3048930..5829e4941a 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientGroupWrapper.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientGroupWrapper.java @@ -30,7 +30,6 @@ import com.alibaba.fastjson.JSON; -import io.openmessaging.api.Action; import io.openmessaging.api.AsyncConsumeContext; import io.openmessaging.api.AsyncMessageListener; import io.openmessaging.api.Message; @@ -40,8 +39,12 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.eventmesh.api.EventMeshAction; +import org.apache.eventmesh.api.EventMeshAsyncConsumeContext; import org.apache.eventmesh.api.RRCallback; import org.apache.eventmesh.common.Constants; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.configuration.EventMeshTCPConfiguration; import org.apache.eventmesh.runtime.constants.EventMeshConstants; @@ -62,11 +65,12 @@ public class ClientGroupWrapper { public static Logger logger = LoggerFactory.getLogger(ClientGroupWrapper.class); - private String groupName; + private String producerGroup; - private String sysId; + private String consumerGroup; - private String dcn; + //can be sysid + ext(eg dcn) + private String sysId; private EventMeshTCPConfiguration eventMeshTCPConfiguration; @@ -98,24 +102,18 @@ public class ClientGroupWrapper { private ConcurrentHashMap> topic2sessionInGroupMapping = new ConcurrentHashMap>(); - private ConcurrentHashMap downstreamMap = new ConcurrentHashMap(); - - public ConcurrentHashMap getDownstreamMap() { - return downstreamMap; - } - public AtomicBoolean producerStarted = new AtomicBoolean(Boolean.FALSE); - public ClientGroupWrapper(String sysId, String dcn, + public ClientGroupWrapper(String sysId, String producerGroup, String consumerGroup, EventMeshTCPServer eventMeshTCPServer, DownstreamDispatchStrategy downstreamDispatchStrategy) { this.sysId = sysId; - this.dcn = dcn; + this.producerGroup = producerGroup; + this.consumerGroup = consumerGroup; this.eventMeshTCPServer = eventMeshTCPServer; this.eventMeshTCPConfiguration = eventMeshTCPServer.getEventMeshTCPConfiguration(); this.eventMeshTcpRetryer = eventMeshTCPServer.getEventMeshTcpRetryer(); this.eventMeshTcpMonitor = eventMeshTCPServer.getEventMeshTcpMonitor(); - this.groupName = EventMeshUtil.buildClientGroup(sysId, dcn); this.downstreamDispatchStrategy = downstreamDispatchStrategy; } @@ -172,8 +170,7 @@ public MQProducerWrapper getMqProducerWrapper() { } public boolean addSubscription(String topic, Session session) throws Exception { - if (session == null - || !StringUtils.equalsIgnoreCase(groupName, EventMeshUtil.buildClientGroup(session.getClient().getSubsystem(), session.getClient().getDcn()))) { + if (session == null || !StringUtils.equalsIgnoreCase(consumerGroup, EventMeshUtil.buildClientGroup(session.getClient().getConsumerGroup()))) { logger.error("addSubscription param error,topic:{},session:{}", topic, session); return false; } @@ -187,9 +184,9 @@ public boolean addSubscription(String topic, Session session) throws Exception { } r = topic2sessionInGroupMapping.get(topic).add(session); if (r) { - logger.info("addSubscription success, group:{} topic:{} client:{}", groupName, topic, session.getClient()); + logger.info("addSubscription success, group:{} topic:{} client:{}", consumerGroup, topic, session.getClient()); } else { - logger.warn("addSubscription fail, group:{} topic:{} client:{}", groupName, topic, session.getClient()); + logger.warn("addSubscription fail, group:{} topic:{} client:{}", consumerGroup, topic, session.getClient()); } } catch (Exception e) { logger.error("addSubscription error! topic:{} client:{}", topic, session.getClient(), e); @@ -202,7 +199,7 @@ public boolean addSubscription(String topic, Session session) throws Exception { public boolean removeSubscription(String topic, Session session) { if (session == null - || !StringUtils.equalsIgnoreCase(groupName, EventMeshUtil.buildClientGroup(session.getClient().getSubsystem(), session.getClient().getDcn()))) { + || !StringUtils.equalsIgnoreCase(consumerGroup, EventMeshUtil.buildClientGroup(session.getClient().getConsumerGroup()))) { logger.error("removeSubscription param error,topic:{},session:{}", topic, session); return false; } @@ -213,14 +210,14 @@ public boolean removeSubscription(String topic, Session session) { if (topic2sessionInGroupMapping.containsKey(topic)) { r = topic2sessionInGroupMapping.get(topic).remove(session); if (r) { - logger.info("removeSubscription remove session success, group:{} topic:{} client:{}", groupName, topic, session.getClient()); + logger.info("removeSubscription remove session success, group:{} topic:{} client:{}", consumerGroup, topic, session.getClient()); } else { - logger.warn("removeSubscription remove session failed, group:{} topic:{} client:{}", groupName, topic, session.getClient()); + logger.warn("removeSubscription remove session failed, group:{} topic:{} client:{}", consumerGroup, topic, session.getClient()); } } if (CollectionUtils.size(topic2sessionInGroupMapping.get(topic)) == 0) { topic2sessionInGroupMapping.remove(topic); - logger.info("removeSubscription remove topic success, group:{} topic:{}", groupName, topic); + logger.info("removeSubscription remove topic success, group:{} topic:{}", consumerGroup, topic); } } catch (Exception e) { logger.error("removeSubscription error! topic:{} client:{}", topic, session.getClient(), e); @@ -237,8 +234,8 @@ public synchronized void startClientGroupProducer() throws Exception { Properties keyValue = new Properties(); // KeyValue keyValue = OMS.newKeyValue(); - keyValue.put("producerGroup", groupName); - keyValue.put("instanceName", EventMeshUtil.buildMeshTcpClientID(sysId, dcn, "PUB", eventMeshTCPConfiguration.eventMeshCluster)); + keyValue.put("producerGroup", producerGroup); + keyValue.put("instanceName", EventMeshUtil.buildMeshTcpClientID(sysId, "PUB", eventMeshTCPConfiguration.eventMeshCluster)); //TODO for defibus keyValue.put("eventMeshIDC", eventMeshTCPConfiguration.eventMeshIDC); @@ -246,7 +243,7 @@ public synchronized void startClientGroupProducer() throws Exception { mqProducerWrapper.init(keyValue); mqProducerWrapper.start(); producerStarted.compareAndSet(false, true); - logger.info("starting producer success, group:{}", groupName); + logger.info("starting producer success, group:{}", producerGroup); } public synchronized void shutdownProducer() throws Exception { @@ -255,17 +252,28 @@ public synchronized void shutdownProducer() throws Exception { } mqProducerWrapper.shutdown(); producerStarted.compareAndSet(true, false); - logger.info("shutdown producer success for group:{}", groupName); + logger.info("shutdown producer success for group:{}", producerGroup); + } + + public String getProducerGroup() { + return producerGroup; + } + + public void setProducerGroup(String producerGroup) { + this.producerGroup = producerGroup; } + public String getConsumerGroup() { + return consumerGroup; + } - public String getGroupName() { - return groupName; + public void setConsumerGroup(String consumerGroup) { + this.consumerGroup = consumerGroup; } public boolean addGroupConsumerSession(Session session) { if (session == null - || !StringUtils.equalsIgnoreCase(groupName, EventMeshUtil.buildClientGroup(session.getClient().getSubsystem(), session.getClient().getDcn()))) { + || !StringUtils.equalsIgnoreCase(consumerGroup, EventMeshUtil.buildClientGroup(session.getClient().getConsumerGroup()))) { logger.error("addGroupConsumerSession param error,session:{}", session); return false; } @@ -275,10 +283,10 @@ public boolean addGroupConsumerSession(Session session) { this.groupLock.writeLock().lockInterruptibly(); r = groupConsumerSessions.add(session); if (r) { - logger.info("addGroupConsumerSession success, group:{} client:{}", groupName, session.getClient()); + logger.info("addGroupConsumerSession success, group:{} client:{}", consumerGroup, session.getClient()); } } catch (Exception e) { - logger.error("addGroupConsumerSession error! group:{} client:{}", groupName, session.getClient(), e); + logger.error("addGroupConsumerSession error! group:{} client:{}", consumerGroup, session.getClient(), e); } finally { this.groupLock.writeLock().unlock(); } @@ -287,7 +295,7 @@ public boolean addGroupConsumerSession(Session session) { public boolean addGroupProducerSession(Session session) { if (session == null - || !StringUtils.equalsIgnoreCase(groupName, EventMeshUtil.buildClientGroup(session.getClient().getSubsystem(), session.getClient().getDcn()))) { + || !StringUtils.equalsIgnoreCase(producerGroup, EventMeshUtil.buildClientGroup(session.getClient().getProducerGroup()))) { logger.error("addGroupProducerSession param error,session:{}", session); return false; } @@ -297,10 +305,10 @@ public boolean addGroupProducerSession(Session session) { this.groupLock.writeLock().lockInterruptibly(); r = groupProducerSessions.add(session); if (r) { - logger.info("addGroupProducerSession success, group:{} client:{}", groupName, session.getClient()); + logger.info("addGroupProducerSession success, group:{} client:{}", producerGroup, session.getClient()); } } catch (Exception e) { - logger.error("addGroupProducerSession error! group:{} client:{}", groupName, session.getClient(), e); + logger.error("addGroupProducerSession error! group:{} client:{}", producerGroup, session.getClient(), e); } finally { this.groupLock.writeLock().unlock(); } @@ -309,7 +317,7 @@ public boolean addGroupProducerSession(Session session) { public boolean removeGroupConsumerSession(Session session) { if (session == null - || !StringUtils.equalsIgnoreCase(groupName, EventMeshUtil.buildClientGroup(session.getClient().getSubsystem(), session.getClient().getDcn()))) { + || !StringUtils.equalsIgnoreCase(consumerGroup, EventMeshUtil.buildClientGroup(session.getClient().getConsumerGroup()))) { logger.error("removeGroupConsumerSession param error,session:{}", session); return false; } @@ -319,10 +327,10 @@ public boolean removeGroupConsumerSession(Session session) { this.groupLock.writeLock().lockInterruptibly(); r = groupConsumerSessions.remove(session); if (r) { - logger.info("removeGroupConsumerSession success, group:{} client:{}", groupName, session.getClient()); + logger.info("removeGroupConsumerSession success, group:{} client:{}", consumerGroup, session.getClient()); } } catch (Exception e) { - logger.error("removeGroupConsumerSession error! group:{} client:{}", groupName, session.getClient(), e); + logger.error("removeGroupConsumerSession error! group:{} client:{}", consumerGroup, session.getClient(), e); } finally { this.groupLock.writeLock().unlock(); } @@ -331,7 +339,7 @@ public boolean removeGroupConsumerSession(Session session) { public boolean removeGroupProducerSession(Session session) { if (session == null - || !StringUtils.equalsIgnoreCase(groupName, EventMeshUtil.buildClientGroup(session.getClient().getSubsystem(), session.getClient().getDcn()))) { + || !StringUtils.equalsIgnoreCase(producerGroup, EventMeshUtil.buildClientGroup(session.getClient().getProducerGroup()))) { logger.error("removeGroupProducerSession param error,session:{}", session); return false; } @@ -341,10 +349,10 @@ public boolean removeGroupProducerSession(Session session) { this.groupLock.writeLock().lockInterruptibly(); r = groupProducerSessions.remove(session); if (r) { - logger.info("removeGroupProducerSession success, group:{} client:{}", groupName, session.getClient()); + logger.info("removeGroupProducerSession success, group:{} client:{}", producerGroup, session.getClient()); } } catch (Exception e) { - logger.error("removeGroupProducerSession error! group:{} client:{}", groupName, session.getClient(), e); + logger.error("removeGroupProducerSession error! group:{} client:{}", producerGroup, session.getClient(), e); } finally { this.groupLock.writeLock().unlock(); } @@ -359,9 +367,9 @@ public synchronized void initClientGroupPersistentConsumer() throws Exception { Properties keyValue = new Properties(); keyValue.put("isBroadcast", "false"); - keyValue.put("consumerGroup", groupName); + keyValue.put("consumerGroup", consumerGroup); keyValue.put("eventMeshIDC", eventMeshTCPConfiguration.eventMeshIDC); - keyValue.put("instanceName", EventMeshUtil.buildMeshTcpClientID(sysId, dcn, "SUB", eventMeshTCPConfiguration.eventMeshCluster)); + keyValue.put("instanceName", EventMeshUtil.buildMeshTcpClientID(sysId, "SUB", eventMeshTCPConfiguration.eventMeshCluster)); persistentMsgConsumer.init(keyValue); // persistentMsgConsumer.registerMessageListener(new EventMeshMessageListenerConcurrently() { @@ -429,7 +437,7 @@ public synchronized void initClientGroupPersistentConsumer() throws Exception { // } // }); inited4Persistent.compareAndSet(false, true); - logger.info("init persistentMsgConsumer success, group:{}", groupName); + logger.info("init persistentMsgConsumer success, group:{}", consumerGroup); } public synchronized void startClientGroupPersistentConsumer() throws Exception { @@ -438,7 +446,7 @@ public synchronized void startClientGroupPersistentConsumer() throws Exception { } persistentMsgConsumer.start(); started4Persistent.compareAndSet(false, true); - logger.info("starting persistentMsgConsumer success, group:{}", groupName); + logger.info("starting persistentMsgConsumer success, group:{}", consumerGroup); } public synchronized void initClientGroupBroadcastConsumer() throws Exception { @@ -448,9 +456,9 @@ public synchronized void initClientGroupBroadcastConsumer() throws Exception { Properties keyValue = new Properties(); keyValue.put("isBroadcast", "true"); - keyValue.put("consumerGroup", groupName); + keyValue.put("consumerGroup", consumerGroup); keyValue.put("eventMeshIDC", eventMeshTCPConfiguration.eventMeshIDC); - keyValue.put("instanceName", EventMeshUtil.buildMeshTcpClientID(sysId, dcn, "SUB", eventMeshTCPConfiguration.eventMeshCluster)); + keyValue.put("instanceName", EventMeshUtil.buildMeshTcpClientID(sysId, "SUB", eventMeshTCPConfiguration.eventMeshCluster)); broadCastMsgConsumer.init(keyValue); // broadCastMsgConsumer.registerMessageListener(new EventMeshMessageListenerConcurrently() { // @Override @@ -504,7 +512,7 @@ public synchronized void initClientGroupBroadcastConsumer() throws Exception { // } // }); inited4Broadcast.compareAndSet(false, true); - logger.info("init broadCastMsgConsumer success, group:{}", groupName); + logger.info("init broadCastMsgConsumer success, group:{}", consumerGroup); } public synchronized void startClientGroupBroadcastConsumer() throws Exception { @@ -513,12 +521,12 @@ public synchronized void startClientGroupBroadcastConsumer() throws Exception { } broadCastMsgConsumer.start(); started4Broadcast.compareAndSet(false, true); - logger.info("starting broadCastMsgConsumer success, group:{}", groupName); + logger.info("starting broadCastMsgConsumer success, group:{}", consumerGroup); } - public void subscribe(String topic) throws Exception { + public void subscribe(SubscriptionItem subscriptionItem) throws Exception { AsyncMessageListener listener = null; - if (EventMeshUtil.isBroadcast(topic)) { + if (SubscriptionMode.BROADCASTING.equals(subscriptionItem.getMode())) { listener = new AsyncMessageListener() { @Override public void consume(Message message, AsyncConsumeContext context) { @@ -528,16 +536,20 @@ public void consume(Message message, AsyncConsumeContext context) { message.getSystemProperties().put(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())); message.getSystemProperties().put(EventMeshConstants.REQ_RECEIVE_EVENTMESH_IP, eventMeshTCPConfiguration.eventMeshServerIp); + EventMeshAsyncConsumeContext eventMeshAsyncConsumeContext = (EventMeshAsyncConsumeContext) context; if (CollectionUtils.isEmpty(groupConsumerSessions)) { logger.warn("found no session to downstream broadcast msg"); // context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); // context.ack(); - context.commit(Action.CommitMessage); + eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage); return; } Iterator sessionsItr = groupConsumerSessions.iterator(); + DownStreamMsgContext downStreamMsgContext = + new DownStreamMsgContext(message, null, broadCastMsgConsumer, eventMeshAsyncConsumeContext.getAbstractContext(), false, subscriptionItem); + while (sessionsItr.hasNext()) { Session session = sessionsItr.next(); @@ -546,26 +558,25 @@ public void consume(Message message, AsyncConsumeContext context) { continue; } - DownStreamMsgContext downStreamMsgContext = - new DownStreamMsgContext(message, session, broadCastMsgConsumer, broadCastMsgConsumer.getContext(), false); - - if (session.isCanDownStream()) { - session.downstreamMsg(downStreamMsgContext); - continue; - } + downStreamMsgContext.session = session; - logger.warn("downstream broadcast msg,session is busy,dispatch retry,seq:{}, session:{}, bizSeq:{}", downStreamMsgContext.seq, downStreamMsgContext.session.getClient(), EventMeshUtil.getMessageBizSeq(downStreamMsgContext.msgExt)); - long delayTime = EventMeshUtil.isService(downStreamMsgContext.msgExt.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION)) ? 0 : eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpMsgRetryDelayInMills; - downStreamMsgContext.delay(delayTime); - eventMeshTcpRetryer.pushRetry(downStreamMsgContext); + //downstream broadcast msg asynchronously + eventMeshTCPServer.getBroadcastMsgDownstreamExecutorService().submit(new Runnable() { + @Override + public void run() { + //msg put in eventmesh,waiting client ack + session.getPusher().unAckMsg(downStreamMsgContext.seq, downStreamMsgContext); + session.downstreamMsg(downStreamMsgContext); + } + }); } // context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); // context.ack(); - context.commit(Action.CommitMessage); + eventMeshAsyncConsumeContext.commit(EventMeshAction.ManualAck); } }; - broadCastMsgConsumer.subscribe(topic, listener); + broadCastMsgConsumer.subscribe(subscriptionItem.getTopic(), listener); } else { listener = new AsyncMessageListener() { @Override @@ -575,7 +586,8 @@ public void consume(Message message, AsyncConsumeContext context) { message.getSystemProperties().put(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())); message.getSystemProperties().put(EventMeshConstants.REQ_RECEIVE_EVENTMESH_IP, eventMeshTCPConfiguration.eventMeshServerIp); - Session session = downstreamDispatchStrategy.select(groupName, topic, groupConsumerSessions); + EventMeshAsyncConsumeContext eventMeshAsyncConsumeContext = (EventMeshAsyncConsumeContext) context; + Session session = downstreamDispatchStrategy.select(consumerGroup, topic, groupConsumerSessions); String bizSeqNo = EventMeshUtil.getMessageBizSeq(message); if (session == null) { try { @@ -588,14 +600,14 @@ public void consume(Message message, AsyncConsumeContext context) { sendBackFromEventMeshIp = message.getSystemProperties(EventMeshConstants.EVENTMESH_SEND_BACK_IP); } - logger.error("found no session to downstream msg,groupName:{}, topic:{}, bizSeqNo:{}", groupName, topic, bizSeqNo); + logger.error("found no session to downstream msg,groupName:{}, topic:{}, bizSeqNo:{}, sendBackTimes:{}, sendBackFromEventMeshIp:{}", consumerGroup, topic, bizSeqNo, sendBackTimes, sendBackFromEventMeshIp); if (sendBackTimes >= eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpSendBackMaxTimes) { - logger.error("sendBack to broker over max times:{}, groupName:{}, topic:{}, bizSeqNo:{}", eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpSendBackMaxTimes, groupName, topic, bizSeqNo); + logger.error("sendBack to broker over max times:{}, groupName:{}, topic:{}, bizSeqNo:{}", eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpSendBackMaxTimes, consumerGroup, topic, bizSeqNo); } else { sendBackTimes++; message.getSystemProperties().put(EventMeshConstants.EVENTMESH_SEND_BACK_TIMES, sendBackTimes.toString()); - message.getSystemProperties().put(EventMeshConstants.EVENTMESH_SEND_BACK_IP, sendBackFromEventMeshIp); + message.getSystemProperties().put(EventMeshConstants.EVENTMESH_SEND_BACK_IP, eventMeshTCPConfiguration.eventMeshServerIp); sendMsgBackToBroker(message, bizSeqNo); } } catch (Exception e) { @@ -604,53 +616,36 @@ public void consume(Message message, AsyncConsumeContext context) { // context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); // context.ack(); - context.commit(Action.CommitMessage); + eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage); return; } DownStreamMsgContext downStreamMsgContext = - new DownStreamMsgContext(message, session, persistentMsgConsumer, persistentMsgConsumer.getContext(), false); - - if (downstreamMap.size() < eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpDownStreamMapSize) { - downstreamMap.putIfAbsent(downStreamMsgContext.seq, downStreamMsgContext); - } else { - logger.warn("downStreamMap is full,group:{}", groupName); - } - - if (session.isCanDownStream()) { - session.downstreamMsg(downStreamMsgContext); -// context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); -// context.ack(); - context.commit(Action.CommitMessage); - return; - } - - logger.warn("session is busy,dispatch retry,seq:{}, session:{}, bizSeq:{}", downStreamMsgContext.seq, downStreamMsgContext.session.getClient(), bizSeqNo); - long delayTime = EventMeshUtil.isService(downStreamMsgContext.msgExt.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION)) ? 0 : eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpMsgRetryDelayInMills; - downStreamMsgContext.delay(delayTime); - eventMeshTcpRetryer.pushRetry(downStreamMsgContext); - + new DownStreamMsgContext(message, session, persistentMsgConsumer, eventMeshAsyncConsumeContext.getAbstractContext(), false, subscriptionItem); + //msg put in eventmesh,waiting client ack + session.getPusher().unAckMsg(downStreamMsgContext.seq, downStreamMsgContext); + session.downstreamMsg(downStreamMsgContext); // context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); // context.ack(); - context.commit(Action.CommitMessage); + eventMeshAsyncConsumeContext.commit(EventMeshAction.ManualAck); } }; - persistentMsgConsumer.subscribe(topic, listener); + persistentMsgConsumer.subscribe(subscriptionItem.getTopic(), listener); } } - public void unsubscribe(String topic) throws Exception { - if (EventMeshUtil.isBroadcast(topic)) { - broadCastMsgConsumer.unsubscribe(topic); + public void unsubscribe(SubscriptionItem subscriptionItem) throws Exception { + if (SubscriptionMode.BROADCASTING.equals(subscriptionItem.getMode())) { + broadCastMsgConsumer.unsubscribe(subscriptionItem.getTopic()); } else { - persistentMsgConsumer.unsubscribe(topic); + persistentMsgConsumer.unsubscribe(subscriptionItem.getTopic()); } } public synchronized void shutdownBroadCastConsumer() throws Exception { if (started4Broadcast.get()) { broadCastMsgConsumer.shutdown(); - logger.info("broadcast consumer group:{} shutdown...", groupName); + logger.info("broadcast consumer group:{} shutdown...", consumerGroup); } started4Broadcast.compareAndSet(true, false); inited4Broadcast.compareAndSet(true, false); @@ -661,7 +656,7 @@ public synchronized void shutdownPersistentConsumer() throws Exception { if (started4Persistent.get()) { persistentMsgConsumer.shutdown(); - logger.info("persistent consumer group:{} shutdown...", groupName); + logger.info("persistent consumer group:{} shutdown...", consumerGroup); } started4Persistent.compareAndSet(true, false); inited4Persistent.compareAndSet(true, false); @@ -669,32 +664,11 @@ public synchronized void shutdownPersistentConsumer() throws Exception { } public Set getGroupConsumerSessions() { - Set res = null; - try { - this.groupLock.readLock().lockInterruptibly(); - res = groupConsumerSessions; - } catch (Exception e) { - } finally { - this.groupLock.readLock().unlock(); - } - return res; + return groupConsumerSessions; } - public Set getGroupProducerSessions() { - Set res = null; - try { - this.groupLock.readLock().lockInterruptibly(); - res = groupProducerSessions; - } catch (Exception e) { - } finally { - this.groupLock.readLock().unlock(); - } - return res; - } - - public void setGroupName(String groupName) { - this.groupName = groupName; + return groupProducerSessions; } public EventMeshTCPConfiguration getEventMeshTCPConfiguration() { @@ -744,7 +718,7 @@ private String pushMsgToEventMesh(Message msg, String ip, int port) throws Excep paramValues.add("msg"); paramValues.add(JSON.toJSONString(msg)); paramValues.add("group"); - paramValues.add(groupName); + paramValues.add(consumerGroup); result = HttpTinyClient.httpPost( targetUrl.toString(), @@ -778,12 +752,12 @@ private void sendMsgBackToBroker(Message msg, String bizSeqNo) throws Exception send(new UpStreamMsgContext(null, null, msg), new SendCallback() { @Override public void onSuccess(SendResult sendResult) { - logger.info("consumerGroup:{} consume fail, sendMessageBack success, bizSeqno:{}, topic:{}", groupName, bizSeqNo, topic); + logger.info("consumerGroup:{} consume fail, sendMessageBack success, bizSeqno:{}, topic:{}", consumerGroup, bizSeqNo, topic); } @Override public void onException(OnExceptionContext context) { - logger.warn("consumerGroup:{} consume fail, sendMessageBack fail, bizSeqno:{}, topic:{}", groupName, bizSeqNo, topic); + logger.warn("consumerGroup:{} consume fail, sendMessageBack fail, bizSeqno:{}, topic:{}", consumerGroup, bizSeqNo, topic); } // @Override diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientSessionGroupMapping.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientSessionGroupMapping.java index a33baf1b19..a5a4b409aa 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientSessionGroupMapping.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientSessionGroupMapping.java @@ -19,15 +19,11 @@ import java.lang.ref.WeakReference; import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; @@ -37,6 +33,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.ThreadUtil; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; @@ -45,7 +43,6 @@ import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.dispatch.FreePriorityDispatchStrategy; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.SessionState; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push.ClientAckContext; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push.DownStreamMsgContext; import org.apache.eventmesh.runtime.util.EventMeshUtil; import org.apache.eventmesh.runtime.util.RemotingHelper; @@ -59,9 +56,9 @@ public class ClientSessionGroupMapping { private ConcurrentHashMap sessionTable = new ConcurrentHashMap<>(); - private ConcurrentHashMap clientGroupMap = new ConcurrentHashMap(); + private ConcurrentHashMap clientGroupMap = new ConcurrentHashMap(); - private ConcurrentHashMap lockMap = new ConcurrentHashMap(); + private ConcurrentHashMap lockMap = new ConcurrentHashMap(); private EventMeshTCPServer eventMeshTCPServer; @@ -77,8 +74,8 @@ public void setEventMeshTCPServer(EventMeshTCPServer eventMeshTCPServer) { this.eventMeshTCPServer = eventMeshTCPServer; } - public ClientGroupWrapper getClientGroupWrapper(String groupName) { - return MapUtils.getObject(clientGroupMap, groupName, null); + public ClientGroupWrapper getClientGroupWrapper(String sysId) { + return MapUtils.getObject(clientGroupMap, sysId, null); } public Session getSession(ChannelHandlerContext ctx) { @@ -179,30 +176,28 @@ public void operationComplete(ChannelFuture future) throws Exception { } } - private ClientGroupWrapper constructClientGroupWrapper(String sysId, String dcn, + private ClientGroupWrapper constructClientGroupWrapper(String sysId, String producerGroup, String consumerGroup, EventMeshTCPServer eventMeshTCPServer, DownstreamDispatchStrategy downstreamDispatchStrategy) { - return new ClientGroupWrapper(sysId, dcn - , eventMeshTCPServer, downstreamDispatchStrategy); + return new ClientGroupWrapper(sysId, producerGroup, consumerGroup, eventMeshTCPServer, downstreamDispatchStrategy); } private void initClientGroupWrapper(UserAgent user, Session session) throws Exception { - final String clientGroup = EventMeshUtil.buildClientGroup(user.getSubsystem(), user.getDcn()); - if (!lockMap.containsKey(clientGroup)) { - Object obj = lockMap.putIfAbsent(clientGroup, new Object()); + if (!lockMap.containsKey(user.getSubsystem())) { + Object obj = lockMap.putIfAbsent(user.getSubsystem(), new Object()); if (obj == null) { - logger.info("add lock to map for group:{}", clientGroup); + logger.info("add lock to map for subsystem:{}", user.getSubsystem()); } } - synchronized (lockMap.get(clientGroup)) { - if (!clientGroupMap.containsKey(clientGroup)) { - ClientGroupWrapper cgw = constructClientGroupWrapper(user.getSubsystem(), user.getDcn() - , eventMeshTCPServer, new FreePriorityDispatchStrategy()); - clientGroupMap.put(clientGroup, cgw); - logger.info("create new ClientGroupWrapper,group:{}", clientGroup); + synchronized (lockMap.get(user.getSubsystem())) { + if (!clientGroupMap.containsKey(user.getSubsystem())) { + ClientGroupWrapper cgw = constructClientGroupWrapper(user.getSubsystem(), user.getProducerGroup(), + user.getConsumerGroup(), eventMeshTCPServer, new FreePriorityDispatchStrategy()); + clientGroupMap.put(user.getSubsystem(), cgw); + logger.info("create new ClientGroupWrapper, subsystem:{}", user.getSubsystem()); } - ClientGroupWrapper cgw = clientGroupMap.get(clientGroup); + ClientGroupWrapper cgw = clientGroupMap.get(user.getSubsystem()); if (EventMeshConstants.PURPOSE_PUB.equals(user.getPurpose())) { startClientGroupProducer(cgw, session); @@ -243,11 +238,10 @@ private void initClientGroupConsumser(ClientGroupWrapper cgw) throws Exception { } private void startClientGroupConsumer(Session session) throws Exception { - final String clientGroup = EventMeshUtil.buildClientGroup(session.getClient().getSubsystem(), session.getClient().getDcn()); - if (!lockMap.containsKey(clientGroup)) { - lockMap.putIfAbsent(clientGroup, new Object()); + if (!lockMap.containsKey(session.getClient().getSubsystem())) { + lockMap.putIfAbsent(session.getClient().getSubsystem(), new Object()); } - synchronized (lockMap.get(clientGroup)) { + synchronized (lockMap.get(session.getClient().getSubsystem())) { logger.info("readySession session[{}]", session); ClientGroupWrapper cgw = session.getClientGroupWrapper().get(); @@ -284,10 +278,10 @@ private void cleanClientGroupWrapperByClosePub(Session session) throws Exception * @param session */ private void cleanSubscriptionInSession(Session session) throws Exception { - for (String topic : session.getSessionContext().subscribeTopics.values()) { - session.getClientGroupWrapper().get().removeSubscription(topic, session); - if (!session.getClientGroupWrapper().get().hasSubscription(topic)) { - session.getClientGroupWrapper().get().unsubscribe(topic); + for (SubscriptionItem item : session.getSessionContext().subscribeTopics.values()) { + session.getClientGroupWrapper().get().removeSubscription(item.getTopic(), session); + if (!session.getClientGroupWrapper().get().hasSubscription(item.getTopic())) { + session.getClientGroupWrapper().get().unsubscribe(item); } } } @@ -298,21 +292,24 @@ private void cleanSubscriptionInSession(Session session) throws Exception { * @param session */ private void handleUnackMsgsInSession(Session session) { - ConcurrentHashMap unAckMsg = session.getPusher().getPushContext().getUnAckMsg(); + ConcurrentHashMap unAckMsg = session.getPusher().getUnAckMsg(); if (unAckMsg.size() > 0 && session.getClientGroupWrapper().get().getGroupConsumerSessions().size() > 0) { - for (Map.Entry entry : unAckMsg.entrySet()) { - ClientAckContext ackContext = entry.getValue(); - if (EventMeshUtil.isBroadcast(ackContext.getMsgs().get(0).getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION))) { - logger.warn("exist broadcast msg unack when closeSession,seq:{},bizSeq:{},client:{}", ackContext.getSeq(), EventMeshUtil.getMessageBizSeq(ackContext.getMsgs().get(0)), session.getClient()); + for (Map.Entry entry : unAckMsg.entrySet()) { + DownStreamMsgContext downStreamMsgContext = entry.getValue(); + if (SubscriptionMode.BROADCASTING.equals(downStreamMsgContext.subscriptionItem.getMode())) { + logger.warn("exist broadcast msg unack when closeSession,seq:{},bizSeq:{},client:{}", downStreamMsgContext.seq, EventMeshUtil.getMessageBizSeq(downStreamMsgContext.msgExt), session.getClient()); continue; } - List list = new ArrayList<>(session.getClientGroupWrapper().get().getGroupConsumerSessions()); - Collections.shuffle(list); - DownStreamMsgContext downStreamMsgContext = new DownStreamMsgContext(ackContext.getMsgs().get(0), list.get(0), ackContext.getConsumer(), ackContext.getContext(), false); - - downStreamMsgContext.delay(0L); - eventMeshTCPServer.getEventMeshTcpRetryer().pushRetry(downStreamMsgContext); - logger.warn("rePush msg form unAckMsgs,seq:{},rePushSeq:{},rePushClient:{}", entry.getKey(), downStreamMsgContext.seq, downStreamMsgContext.session.getClient()); + Session reChooseSession = session.getClientGroupWrapper().get().getDownstreamDispatchStrategy().select(session.getClientGroupWrapper().get().getConsumerGroup() + , downStreamMsgContext.msgExt.getTopic() + , session.getClientGroupWrapper().get().groupConsumerSessions); + if(reChooseSession != null){ + downStreamMsgContext.session = reChooseSession; + reChooseSession.downstreamMsg(downStreamMsgContext); + logger.info("rePush msg form unAckMsgs,seq:{},rePushClient:{}", entry.getKey(), downStreamMsgContext.session.getClient()); + }else{ + logger.warn("select session fail in handleUnackMsgsInSession,seq:{},topic:{}", entry.getKey(), downStreamMsgContext.msgExt.getTopic()); + } } } } @@ -328,9 +325,9 @@ private void cleanClientGroupWrapperCommon(Session session) throws Exception { && (session.getClientGroupWrapper().get().getGroupProducerSessions().size() == 0)) { shutdownClientGroupProducer(session); - clientGroupMap.remove(session.getClientGroupWrapper().get().getGroupName()); - lockMap.remove(session.getClientGroupWrapper().get().getGroupName()); - logger.info("remove clientGroupWrapper group[{}]", session.getClientGroupWrapper().get().getGroupName()); + clientGroupMap.remove(session.getClientGroupWrapper().get().getSysId()); + lockMap.remove(session.getClientGroupWrapper().get().getSysId()); + logger.info("remove clientGroupWrapper subsystem[{}]", session.getClientGroupWrapper().get().getSysId()); } } @@ -371,46 +368,25 @@ public void run() { }, 1000, eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpSessionExpiredInMills, TimeUnit.MILLISECONDS); } - private void initSessionAckContextCleaner() { + private void initDownStreamMsgContextCleaner() { eventMeshTCPServer.getScheduler().scheduleAtFixedRate(new Runnable() { @Override public void run() { + + //scan non-broadcast msg Iterator sessionIterator = sessionTable.values().iterator(); while (sessionIterator.hasNext()) { Session tmp = sessionIterator.next(); - for (Map.Entry entry : tmp.getPusher().getPushContext().getUnAckMsg().entrySet()) { + for (Map.Entry entry : tmp.getPusher().getUnAckMsg().entrySet()) { String seqKey = entry.getKey(); - ClientAckContext clientAckContext = entry.getValue(); - if (!clientAckContext.isExpire()) { - continue; - } - tmp.getPusher().getPushContext().ackMsg(seqKey); - tmp.getPusher().getPushContext().getUnAckMsg().remove(seqKey); - logger.warn("remove expire clientAckContext, session:{}, topic:{}, seq:{}", tmp, - clientAckContext.getMsgs().get(0).getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION), seqKey); - } - } - } - }, 1000, 5 * 1000, TimeUnit.MILLISECONDS); - } - - private void initDownStreamMsgContextCleaner() { - eventMeshTCPServer.getScheduler().scheduleAtFixedRate(new Runnable() { - @Override - public void run() { - Iterator cgwIterator = clientGroupMap.values().iterator(); - while (cgwIterator.hasNext()) { - ClientGroupWrapper cgw = cgwIterator.next(); - for (Map.Entry entry : cgw.getDownstreamMap().entrySet()) { - String seq = entry.getKey(); DownStreamMsgContext downStreamMsgContext = entry.getValue(); if (!downStreamMsgContext.isExpire()) { continue; } - cgw.getDownstreamMap().get(seq).ackMsg(); - cgw.getDownstreamMap().remove(seq); - logger.warn("remove expire DownStreamMsgContext,group:{}, topic:{}, seq:{}", cgw.getGroupName(), - downStreamMsgContext.msgExt.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION), seq); + downStreamMsgContext.ackMsg(); + tmp.getPusher().getUnAckMsg().remove(seqKey); + logger.warn("remove expire downStreamMsgContext, session:{}, topic:{}, seq:{}", tmp, + downStreamMsgContext.msgExt.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION), seqKey); } } } @@ -420,7 +396,6 @@ public void run() { public void init() throws Exception { initSessionCleaner(); - initSessionAckContextCleaner(); initDownStreamMsgContextCleaner(); logger.info("ClientSessionGroupMapping inited......"); } @@ -450,40 +425,6 @@ public ConcurrentHashMap getClientGroupMap() { return clientGroupMap; } - public HashMap statDCNSystemInfo() { - HashMap result = new HashMap(); - if (!sessionTable.isEmpty()) { - for (Session session : sessionTable.values()) { - String key = session.getClient().getDcn() + "|" + session.getClient().getSubsystem(); - if (!result.containsKey(key)) { - result.put(key, new AtomicInteger(1)); - } else { - result.get(key).incrementAndGet(); - } - } - } - return result; - } - - public HashMap statDCNSystemInfoByPurpose(String purpose) { - HashMap result = new HashMap(); - if (!sessionTable.isEmpty()) { - for (Session session : sessionTable.values()) { - if (!StringUtils.equals(session.getClient().getPurpose(), purpose)) { - continue; - } - - String key = session.getClient().getDcn() + "|" + session.getClient().getSubsystem() + "|" + purpose; - if (!result.containsKey(key)) { - result.put(key, new AtomicInteger(1)); - } else { - result.get(key).incrementAndGet(); - } - } - } - return result; - } - public Map> prepareEventMeshClientDistributionData() { Map> result = null; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/dispatch/FreePriorityDispatchStrategy.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/dispatch/FreePriorityDispatchStrategy.java index 77971583ca..4e9e4d5936 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/dispatch/FreePriorityDispatchStrategy.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/dispatch/FreePriorityDispatchStrategy.java @@ -41,25 +41,26 @@ public Session select(String group, String topic, Set groupConsumerSess } List filtered = new ArrayList(); - List canDownSessions = new ArrayList<>(); + List isolatedSessions = new ArrayList<>(); for (Session session : groupConsumerSessions) { if (!session.isAvailable(topic)) { continue; } - if (session.isDownStreamBusy()) { - canDownSessions.add(session); + if (session.isIsolated()) { + isolatedSessions.add(session); + logger.info("session is not available because session is isolated,isolateTime:{},client:{}",session.getIsolateTime(), session.getClient()); continue; } filtered.add(session); } if (CollectionUtils.isEmpty(filtered)) { - if (CollectionUtils.isEmpty(canDownSessions)) { + if (CollectionUtils.isEmpty(isolatedSessions)) { logger.warn("all sessions can't downstream msg"); return null; } else { - logger.warn("all sessions are busy,group:{},topic:{}", group, topic); - filtered.addAll(canDownSessions); + logger.warn("all sessions are isolated,group:{},topic:{}", group, topic); + filtered.addAll(isolatedSessions); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/Session.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/Session.java index 223974fe95..ddfced04fc 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/Session.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/Session.java @@ -32,10 +32,9 @@ import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.tcp.Header; -import org.apache.eventmesh.common.protocol.tcp.OPStatus; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.tcp.*; import org.apache.eventmesh.common.protocol.tcp.Package; -import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.runtime.configuration.EventMeshTCPConfiguration; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientGroupWrapper; @@ -162,27 +161,26 @@ public void setListenRequestSeq(String listenRequestSeq) { this.listenRequestSeq = listenRequestSeq; } - public void subscribe(List topics) throws Exception { - for (String topic : topics) { - sessionContext.subscribeTopics.putIfAbsent(topic, topic); - clientGroupWrapper.get().subscribe(topic); + public void subscribe(List items) throws Exception { + for (SubscriptionItem item : items) { + sessionContext.subscribeTopics.putIfAbsent(item.getTopic(), item); + clientGroupWrapper.get().subscribe(item); - clientGroupWrapper.get().getMqProducerWrapper().getMeshMQProducer().getDefaultTopicRouteInfoFromNameServer(topic, - EventMeshConstants.DEFAULT_TIME_OUT_MILLS); + clientGroupWrapper.get().getMqProducerWrapper().getMeshMQProducer().checkTopicExist(item.getTopic()); - clientGroupWrapper.get().addSubscription(topic, this); - subscribeLogger.info("subscribe|succeed|topic={}|user={}", topic, client); + clientGroupWrapper.get().addSubscription(item.getTopic(), this); + subscribeLogger.info("subscribe|succeed|topic={}|user={}", item.getTopic(), client); } } - public void unsubscribe(List topics) throws Exception { - for (String topic : topics) { - sessionContext.subscribeTopics.remove(topic); - clientGroupWrapper.get().removeSubscription(topic, this); + public void unsubscribe(List items) throws Exception { + for (SubscriptionItem item : items) { + sessionContext.subscribeTopics.remove(item.getTopic()); + clientGroupWrapper.get().removeSubscription(item.getTopic(), this); - if (!clientGroupWrapper.get().hasSubscription(topic)) { - clientGroupWrapper.get().unsubscribe(topic); - subscribeLogger.info("unSubscribe|succeed|topic={}|lastUser={}", topic, client); + if (!clientGroupWrapper.get().hasSubscription(item.getTopic())) { + clientGroupWrapper.get().unsubscribe(item); + subscribeLogger.info("unSubscribe|succeed|topic={}|lastUser={}", item.getTopic(), client); } } } @@ -200,14 +198,6 @@ public void downstreamMsg(DownStreamMsgContext downStreamMsgContext) { pusher.push(downStreamMsgContext); } - public boolean isDownStreamBusy() { - return pusher.isBusy(); - } - - public boolean isCanDownStream() { - return pusher.isCanDownStream(); - } - public boolean isIsolated() { return System.currentTimeMillis() < isolateTime; } @@ -235,21 +225,10 @@ public void operationComplete(ChannelFuture future) throws Exception { } } - /** - * ACK MSG - * - * @param seq - */ - public void ackMsg(String seq) { - logger.info("ackMsg start,seq:{}", seq); - pusher.getPushContext().ackMsg(seq); - logger.info("ackMsg end,seq:{}", seq); - } - @Override public String toString() { return "Session{" + - "group=" + clientGroupWrapper.get().getGroupName() + + "sysId=" + clientGroupWrapper.get().getSysId() + ",remoteAddr=" + RemotingHelper.parseSocketAddressAddr(remoteAddress) + ",client=" + client + ",sessionState=" + sessionState + @@ -335,25 +314,22 @@ public void setIsolateTime(long isolateTime) { public boolean isAvailable(String topic) { if (SessionState.CLOSED == sessionState) { - logger.warn("session is not available because session has been closed"); + logger.warn("session is not available because session has been closed,topic:{},client:{}", topic, client); return false; } if (!sessionContext.subscribeTopics.containsKey(topic)) { - logger.warn("session is not available because session has not subscribe topic:{}", topic); - return false; - } - if (isIsolated()) { - logger.warn("session is not available because session is isolated,isolateTime:{}", isolateTime); + logger.warn("session is not available because session has not subscribe topic:{},client:{}", topic,client); return false; } + return true; } - @Override - public int hashCode() { - int code = 37 + (client != null ? client.hashCode() : 0) + (context != null ? context.hashCode() : 0) - + (sessionState != null ? sessionState.hashCode() : 0); - return code; - } +// @Override +// public int hashCode() { +// int code = 37 + (client != null ? client.hashCode() : 0) + (context != null ? context.hashCode() : 0) +// + (sessionState != null ? sessionState.hashCode() : 0); +// return code; +// } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/SessionContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/SessionContext.java index 9d5b22e639..e8f851baec 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/SessionContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/SessionContext.java @@ -20,6 +20,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.runtime.constants.EventMeshConstants; public class SessionContext { @@ -28,7 +29,7 @@ public class SessionContext { public ConcurrentHashMap sendTopics = new ConcurrentHashMap(); - public ConcurrentHashMap subscribeTopics = new ConcurrentHashMap(); + public ConcurrentHashMap subscribeTopics = new ConcurrentHashMap(); public long createTime = System.currentTimeMillis(); @@ -38,7 +39,7 @@ public SessionContext(Session session) { @Override public String toString() { - return "SessionContext{subscribeTopics=" + subscribeTopics.keySet() + return "SessionContext{subscribeTopics=" + subscribeTopics + ",sendTopics=" + sendTopics.keySet() + ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + "}"; } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/ClientAckContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/ClientAckContext.java index 0f322d96e4..015fb467a6 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/ClientAckContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/ClientAckContext.java @@ -22,6 +22,7 @@ import io.openmessaging.api.Message; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.api.AbstractContext; import org.apache.eventmesh.common.Constants; @@ -53,7 +54,9 @@ public ClientAckContext(String seq, AbstractContext context, List msgs, this.msgs = msgs; this.consumer = consumer; this.createTime = System.currentTimeMillis(); - this.expireTime = System.currentTimeMillis() + Long.parseLong(msgs.get(0).getUserProperties(EventMeshConstants.PROPERTY_MESSAGE_TTL)); + String ttlStr = msgs.get(0).getUserProperties(EventMeshConstants.PROPERTY_MESSAGE_TTL); + long ttl = StringUtils.isNumeric(ttlStr)? Long.parseLong(ttlStr) : EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; + this.expireTime = System.currentTimeMillis() + ttl; } public boolean isExpire() { diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/DownStreamMsgContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/DownStreamMsgContext.java index 06d088de96..8e441bd5aa 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/DownStreamMsgContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/DownStreamMsgContext.java @@ -24,9 +24,12 @@ import io.openmessaging.api.Message; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.api.AbstractContext; import org.apache.eventmesh.common.Constants; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.plugin.MQConsumerWrapper; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; @@ -50,6 +53,8 @@ public class DownStreamMsgContext implements Delayed { public int retryTimes; + public SubscriptionItem subscriptionItem; + private long executeTime; public long lastPushTime; @@ -60,7 +65,7 @@ public class DownStreamMsgContext implements Delayed { public boolean msgFromOtherEventMesh; - public DownStreamMsgContext(Message msgExt, Session session, MQConsumerWrapper consumer, AbstractContext consumeConcurrentlyContext, boolean msgFromOtherEventMesh) { + public DownStreamMsgContext(Message msgExt, Session session, MQConsumerWrapper consumer, AbstractContext consumeConcurrentlyContext, boolean msgFromOtherEventMesh, SubscriptionItem subscriptionItem) { this.seq = String.valueOf(ServerGlobal.getInstance().getMsgCounter().incrementAndGet()); this.msgExt = msgExt; this.session = session; @@ -70,7 +75,10 @@ public DownStreamMsgContext(Message msgExt, Session session, MQConsumerWrapper c this.lastPushTime = System.currentTimeMillis(); this.executeTime = System.currentTimeMillis(); this.createTime = System.currentTimeMillis(); - this.expireTime = System.currentTimeMillis() + Long.parseLong(msgExt.getUserProperties("TTL")); + this.subscriptionItem = subscriptionItem; + String ttlStr = msgExt.getUserProperties("TTL"); + long ttl = StringUtils.isNumeric(ttlStr) ? Long.parseLong(ttlStr) : EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; + this.expireTime = System.currentTimeMillis() + ttl; this.msgFromOtherEventMesh = msgFromOtherEventMesh; } @@ -85,10 +93,10 @@ public void ackMsg() { consumer.updateOffset(msgs, consumeConcurrentlyContext); // ConsumeMessageService consumeMessageService = consumer.getDefaultMQPushConsumer().getDefaultMQPushConsumerImpl().getConsumeMessageService(); // ((ConsumeMessageConcurrentlyService)consumeMessageService).updateOffset(msgs, consumeConcurrentlyContext); - logger.info("ackMsg topic:{}, bizSeq:{}", msgs.get(0).getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION), + logger.info("ackMsg seq:{}, topic:{}, bizSeq:{}", seq, msgs.get(0).getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION), msgs.get(0).getSystemProperties(EventMeshConstants.PROPERTY_MESSAGE_KEYS)); } else { - logger.warn("ackMsg failed,consumer is null:{}, context is null:{} , msgs is null:{}", consumer == null, consumeConcurrentlyContext == null, msgExt == null); + logger.warn("ackMsg seq:{} failed,consumer is null:{}, context is null:{} , msgs is null:{}", seq, consumer == null, consumeConcurrentlyContext == null, msgExt == null); } } @@ -100,11 +108,12 @@ public void delay(long delay) { public String toString() { return "DownStreamMsgContext{" + ",seq=" + seq + - ",client=" + session.getClient() + + ",client=" + (session == null ? null : session.getClient()) + ",retryTimes=" + retryTimes + ",consumer=" + consumer + // todo ",consumerGroup=" + consumer.getClass().getConsumerGroup() + ",topic=" + msgExt.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION) + + ",subscriptionItem=" + subscriptionItem + ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + ",executeTime=" + DateFormatUtils.format(executeTime, EventMeshConstants.DATE_FORMAT) + ",lastPushTime=" + DateFormatUtils.format(lastPushTime, EventMeshConstants.DATE_FORMAT) + '}'; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/PushContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/PushContext.java index fbe5ac90bd..d236e5b72c 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/PushContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/PushContext.java @@ -17,17 +17,11 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push; -import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; - -import io.openmessaging.api.Message; - import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.time.DateFormatUtils; -import org.apache.eventmesh.api.AbstractContext; import org.apache.eventmesh.runtime.constants.EventMeshConstants; -import org.apache.eventmesh.runtime.core.plugin.MQConsumerWrapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,11 +33,9 @@ public class PushContext { public AtomicLong deliveredMsgsCount = new AtomicLong(0); - public AtomicLong ackedMsgsCount = new AtomicLong(0); - public AtomicLong deliverFailMsgsCount = new AtomicLong(0); - private ConcurrentHashMap unAckMsg = new ConcurrentHashMap(); + private ConcurrentHashMap unAckMsg = new ConcurrentHashMap(); private long createTime = System.currentTimeMillis(); @@ -59,9 +51,8 @@ public void deliverFailMsgCount() { deliverFailMsgsCount.incrementAndGet(); } - public void unAckMsg(String seq, List msg, AbstractContext context, MQConsumerWrapper consumer) { - ClientAckContext ackContext = new ClientAckContext(seq, context, msg, consumer); - unAckMsg.put(seq, ackContext); + public void unAckMsg(String seq, DownStreamMsgContext downStreamMsgContext) { + unAckMsg.put(seq, downStreamMsgContext); logger.info("put msg in unAckMsg,seq:{},unAckMsgSize:{}", seq, getTotalUnackMsgs()); } @@ -69,17 +60,8 @@ public int getTotalUnackMsgs() { return unAckMsg.size(); } - public void ackMsg(String seq) { - if (unAckMsg.containsKey(seq)) { - unAckMsg.get(seq).ackMsg(); - unAckMsg.remove(seq); - ackedMsgsCount.incrementAndGet(); - } else { - logger.warn("ackMsg failed,the seq:{} is not in unAckMsg map", seq); - } - } - public ConcurrentHashMap getUnAckMsg() { + public ConcurrentHashMap getUnAckMsg() { return unAckMsg; } @@ -88,7 +70,6 @@ public String toString() { return "PushContext{" + "deliveredMsgsCount=" + deliveredMsgsCount.longValue() + ",deliverFailCount=" + deliverFailMsgsCount.longValue() + - ",ackedMsgsCount=" + ackedMsgsCount.longValue() + ",unAckMsg=" + CollectionUtils.size(unAckMsg) + ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + '}'; } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/SessionPusher.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/SessionPusher.java index 49c27a457b..12c7cd14e7 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/SessionPusher.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/SessionPusher.java @@ -17,18 +17,13 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push; -import java.util.ArrayList; -import java.util.List; - import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; -import io.openmessaging.api.Message; - +import org.apache.commons.collections4.CollectionUtils; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.tcp.Command; -import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; -import org.apache.eventmesh.common.protocol.tcp.Header; -import org.apache.eventmesh.common.protocol.tcp.OPStatus; +import org.apache.eventmesh.common.protocol.SubcriptionType; +import org.apache.eventmesh.common.protocol.SubscriptionMode; +import org.apache.eventmesh.common.protocol.tcp.*; import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; @@ -36,52 +31,40 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; + public class SessionPusher { private final Logger messageLogger = LoggerFactory.getLogger("message"); private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private Integer unack; + private AtomicLong deliveredMsgsCount = new AtomicLong(0); - private PushContext pushContext = new PushContext(this); + private AtomicLong deliverFailMsgsCount = new AtomicLong(0); - public PushContext getPushContext() { - return pushContext; - } - - public boolean isBusy() { - return pushContext.getTotalUnackMsgs() >= Math.floor(3 * unack / 4); - } - - public boolean isCanDownStream() { - return pushContext.getTotalUnackMsgs() < unack; - } - - public void setPushContext(PushContext pushContext) { - this.pushContext = pushContext; - } + private ConcurrentHashMap downStreamMap = new ConcurrentHashMap(); private Session session; public SessionPusher(Session session) { this.session = session; - unack = (0 == session.getClient().getUnack()) ? session.getEventMeshTCPConfiguration().eventMeshTcpSessionDownstreamUnackSize : session.getClient().getUnack(); } @Override public String toString() { - return "SessionPusher{unack=" + unack - + ",busy=" + isBusy() - + ",canDownStream=" + isCanDownStream() - + ",pushContext=" + pushContext + "}"; + return "SessionPusher{" + + "deliveredMsgsCount=" + deliveredMsgsCount.longValue() + + ",deliverFailCount=" + deliverFailMsgsCount.longValue() + + ",unAckMsg=" + CollectionUtils.size(downStreamMap) + '}'; } public void push(final DownStreamMsgContext downStreamMsgContext) { Command cmd; - if (EventMeshUtil.isBroadcast(downStreamMsgContext.msgExt.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION))) { + if (SubscriptionMode.BROADCASTING.equals(downStreamMsgContext.subscriptionItem.getMode())) { cmd = Command.BROADCAST_MESSAGE_TO_CLIENT; - } else if (EventMeshUtil.isService(downStreamMsgContext.msgExt.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION))) { + } else if (SubcriptionType.SYNC.equals(downStreamMsgContext.subscriptionItem.getType())) { cmd = Command.REQUEST_TO_CLIENT; } else { cmd = Command.ASYNC_MESSAGE_TO_CLIENT; @@ -103,15 +86,6 @@ public void push(final DownStreamMsgContext downStreamMsgContext) { retMsg = e.toString(); } finally { session.getClientGroupWrapper().get().getEventMeshTcpMonitor().getEventMesh2clientMsgNum().incrementAndGet(); - pushContext.deliveredMsgCount(); - - //avoid ack arrives to server prior to callback of the method writeAndFlush,may cause ack problem - List msgExts = new ArrayList(); - msgExts.add(downStreamMsgContext.msgExt); - pushContext.unAckMsg(downStreamMsgContext.seq, - msgExts, - downStreamMsgContext.consumeConcurrentlyContext, - downStreamMsgContext.consumer); session.getContext().writeAndFlush(pkg).addListener( new ChannelFutureListener() { @@ -119,10 +93,7 @@ public void push(final DownStreamMsgContext downStreamMsgContext) { public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { logger.error("downstreamMsg fail,seq:{}, retryTimes:{}, msg:{}", downStreamMsgContext.seq, downStreamMsgContext.retryTimes, downStreamMsgContext.msgExt); - pushContext.deliverFailMsgCount(); - - //push msg failed, remove the msg from unackMap - pushContext.getUnAckMsg().remove(downStreamMsgContext.seq); + deliverFailMsgsCount.incrementAndGet(); //how long to isolate client when push fail long isolateTime = System.currentTimeMillis() + session.getEventMeshTCPConfiguration().eventMeshTcpPushFailIsolateTimeInMills; @@ -130,14 +101,13 @@ public void operationComplete(ChannelFuture future) throws Exception { logger.warn("isolate client:{},isolateTime:{}", session.getClient(), isolateTime); //retry - long delayTime = EventMeshUtil.isService(downStreamMsgContext.msgExt.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION)) ? 0 : session.getEventMeshTCPConfiguration().eventMeshTcpMsgRetryDelayInMills; + long delayTime = SubcriptionType.SYNC.equals(downStreamMsgContext.subscriptionItem.getType()) ? 0 : session.getEventMeshTCPConfiguration().eventMeshTcpMsgRetryDelayInMills; downStreamMsgContext.delay(delayTime); session.getClientGroupWrapper().get().getEventMeshTcpRetryer().pushRetry(downStreamMsgContext); } else { - pushContext.deliveredMsgCount(); + deliveredMsgsCount.incrementAndGet(); logger.info("downstreamMsg success,seq:{}, retryTimes:{}, bizSeq:{}", downStreamMsgContext.seq, downStreamMsgContext.retryTimes, EventMeshUtil.getMessageBizSeq(downStreamMsgContext.msgExt)); - session.getClientGroupWrapper().get().getDownstreamMap().remove(downStreamMsgContext.seq); if (session.isIsolated()) { logger.info("cancel isolated,client:{}", session.getClient()); session.setIsolateTime(System.currentTimeMillis()); @@ -148,4 +118,25 @@ public void operationComplete(ChannelFuture future) throws Exception { ); } } + + public void unAckMsg(String seq, DownStreamMsgContext downStreamMsgContext) { + downStreamMap.put(seq, downStreamMsgContext); + logger.info("put msg in unAckMsg,seq:{},unAckMsgSize:{}", seq, getTotalUnackMsgs()); + } + + public int getTotalUnackMsgs() { + return downStreamMap.size(); + } + + public ConcurrentHashMap getUnAckMsg() { + return downStreamMap; + } + + public AtomicLong getDeliveredMsgsCount() { + return deliveredMsgsCount; + } + + public AtomicLong getDeliverFailMsgsCount() { + return deliverFailMsgsCount; + } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/retry/EventMeshTcpRetryer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/retry/EventMeshTcpRetryer.java index c3d0cceb77..57165a9d85 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/retry/EventMeshTcpRetryer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/retry/EventMeshTcpRetryer.java @@ -28,6 +28,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; +import org.apache.eventmesh.common.protocol.SubcriptionType; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; @@ -74,7 +76,7 @@ public void pushRetry(DownStreamMsgContext downStreamMsgContext) { return; } - int maxRetryTimes = EventMeshUtil.isService(downStreamMsgContext.msgExt.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION)) ? 1 : eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpMsgRetryTimes; + int maxRetryTimes = SubcriptionType.SYNC.equals(downStreamMsgContext.subscriptionItem.getType()) ? 1 : eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpMsgRetryTimes; if (downStreamMsgContext.retryTimes >= maxRetryTimes) { logger.warn("pushRetry fail,retry over maxRetryTimes:{}, retryTimes:{}, seq:{}, bizSeq:{}", maxRetryTimes, downStreamMsgContext.retryTimes, downStreamMsgContext.seq, EventMeshUtil.getMessageBizSeq(downStreamMsgContext.msgExt)); @@ -118,16 +120,15 @@ private void retryHandle(DownStreamMsgContext downStreamMsgContext) { Session rechoosen = null; String topic = downStreamMsgContext.msgExt.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION); - if (!EventMeshUtil.isBroadcast(topic)) { + if (!SubscriptionMode.BROADCASTING.equals(downStreamMsgContext.subscriptionItem.getMode())) { rechoosen = downStreamMsgContext.session.getClientGroupWrapper() - .get().getDownstreamDispatchStrategy().select(downStreamMsgContext.session.getClientGroupWrapper().get().getGroupName() + .get().getDownstreamDispatchStrategy().select(downStreamMsgContext.session.getClientGroupWrapper().get().getSysId() , topic , downStreamMsgContext.session.getClientGroupWrapper().get().getGroupConsumerSessions()); } else { rechoosen = downStreamMsgContext.session; } - if (rechoosen == null) { logger.warn("retry, found no session to downstream msg,seq:{}, retryTimes:{}, bizSeq:{}", downStreamMsgContext.seq, downStreamMsgContext.retryTimes, EventMeshUtil.getMessageBizSeq(downStreamMsgContext.msgExt)); @@ -145,16 +146,8 @@ private void retryHandle(DownStreamMsgContext downStreamMsgContext) { // } } else { downStreamMsgContext.session = rechoosen; - - if (rechoosen.isCanDownStream()) { - rechoosen.downstreamMsg(downStreamMsgContext); - logger.info("retry downStream msg end,seq:{},retryTimes:{},bizSeq:{}", downStreamMsgContext.seq, downStreamMsgContext.retryTimes, EventMeshUtil.getMessageBizSeq(downStreamMsgContext.msgExt)); - } else { - logger.warn("session is busy,push retry again,seq:{}, session:{}, bizSeq:{}", downStreamMsgContext.seq, downStreamMsgContext.session.getClient(), EventMeshUtil.getMessageBizSeq(downStreamMsgContext.msgExt)); - long delayTime = EventMeshUtil.isService(topic) ? 0 : eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpMsgRetryDelayInMills; - downStreamMsgContext.delay(delayTime); - pushRetry(downStreamMsgContext); - } + rechoosen.downstreamMsg(downStreamMsgContext); + logger.info("retry downStream msg end,seq:{},retryTimes:{},bizSeq:{}", downStreamMsgContext.seq, downStreamMsgContext.retryTimes, EventMeshUtil.getMessageBizSeq(downStreamMsgContext.msgExt)); } } catch (Exception e) { logger.error("retry-dispatcher error!", e); @@ -163,9 +156,11 @@ private void retryHandle(DownStreamMsgContext downStreamMsgContext) { private boolean isRetryMsgTimeout(DownStreamMsgContext downStreamMsgContext) { boolean flag = false; - long ttl = Long.parseLong(downStreamMsgContext.msgExt.getUserProperties(EventMeshConstants.PROPERTY_MESSAGE_TTL)); - //TODO 关注是否能取到 - long storeTimestamp = Long.parseLong(downStreamMsgContext.msgExt.getUserProperties(EventMeshConstants.STORE_TIME)); + String ttlStr = downStreamMsgContext.msgExt.getUserProperties(EventMeshConstants.PROPERTY_MESSAGE_TTL); + long ttl = StringUtils.isNumeric(ttlStr)? Long.parseLong(ttlStr) : EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS;; + + String storeTimeStr = downStreamMsgContext.msgExt.getUserProperties(EventMeshConstants.STORE_TIME); + long storeTimestamp = StringUtils.isNumeric(storeTimeStr)? Long.parseLong(storeTimeStr) : 0; String leaveTimeStr = downStreamMsgContext.msgExt.getUserProperties(EventMeshConstants.LEAVE_TIME); long brokerCost = StringUtils.isNumeric(leaveTimeStr) ? Long.parseLong(leaveTimeStr) - storeTimestamp : 0; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/HelloTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/HelloTask.java index 53b97ec66e..161b1d79ae 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/HelloTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/HelloTask.java @@ -101,5 +101,15 @@ private void validateUserAgent(UserAgent user) throws Exception { if (!(StringUtils.equals(EventMeshConstants.PURPOSE_PUB, user.getPurpose()) || StringUtils.equals(EventMeshConstants.PURPOSE_SUB, user.getPurpose()))) { throw new Exception("client purpose config is error"); } + + if (StringUtils.equals(EventMeshConstants.PURPOSE_PUB, user.getPurpose()) + && StringUtils.isBlank(user.getProducerGroup())) { + throw new Exception("client producerGroup cannot be null"); + } + + if (StringUtils.equals(EventMeshConstants.PURPOSE_SUB, user.getPurpose()) + && StringUtils.isBlank(user.getConsumerGroup())) { + throw new Exception("client consumerGroup cannot be null"); + } } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageAckTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageAckTask.java index a8605e92f6..9ddbe4ebeb 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageAckTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageAckTask.java @@ -23,6 +23,7 @@ import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push.ClientAckContext; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push.DownStreamMsgContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,10 +45,12 @@ public void run() { logger.error("MessageAckTask failed, seq cannot be null|user={}", session.getClient()); return; } - ClientAckContext clientAckContext = session.getPusher().getPushContext().getUnAckMsg().get(seq); - if (clientAckContext != null) { - session.ackMsg(seq); - session.getClientGroupWrapper().get().getDownstreamMap().remove(seq); + DownStreamMsgContext downStreamMsgContext = session.getPusher().getUnAckMsg().get(seq); + if (downStreamMsgContext != null) {// ack non-broadcast msg + downStreamMsgContext.ackMsg(); + session.getPusher().getUnAckMsg().remove(seq); + }else { + logger.warn("MessageAckTask, seq:{}, downStreamMsgContext not in downStreamMap,client:{}", seq, session.getClient()); } messageLogger.info("pkg|c2eventMesh|cmd={}|seq=[{}]|user={}|wait={}ms|cost={}ms", cmd, seq, session.getClient(), taskExecuteTime - startTime, System.currentTimeMillis() - startTime); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageTransferTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageTransferTask.java index c903742cdd..028214d865 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageTransferTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageTransferTask.java @@ -84,10 +84,6 @@ public void operationComplete(ChannelFuture future) throws Exception { synchronized (session) { long sendTime = System.currentTimeMillis(); addTimestamp(eventMeshMessage, cmd, sendTime); - if (cmd.equals(Command.REQUEST_TO_SERVER)) { - eventMeshMessage.getProperties().put(EventMeshConstants.PROPERTY_MESSAGE_REPLY_TO, session.getClientGroupWrapper() - .get().getMqProducerWrapper().getMeshMQProducer().buildMQClientId()); - } sendStatus = session.upstreamMsg(pkg.getHeader(), EventMeshUtil.decodeMessage(eventMeshMessage), createSendCallback(replyCmd, taskExecuteTime, eventMeshMessage), startTime, taskExecuteTime); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/SubscribeTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/SubscribeTask.java index e26c66744d..ccacf56b2d 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/SubscribeTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/SubscribeTask.java @@ -22,13 +22,11 @@ import io.netty.channel.ChannelHandlerContext; -import org.apache.eventmesh.common.protocol.tcp.Command; -import org.apache.eventmesh.common.protocol.tcp.Header; -import org.apache.eventmesh.common.protocol.tcp.OPStatus; -import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.common.protocol.tcp.Subscription; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.tcp.*; +import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.util.EventMeshUtil; import org.apache.eventmesh.runtime.util.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,17 +49,14 @@ public void run() { throw new Exception("subscriptionInfo is null"); } - List topicList = new ArrayList<>(); + List subscriptionItems = new ArrayList<>(); for (int i = 0; i < subscriptionInfo.getTopicList().size(); i++) { - String topic = subscriptionInfo.getTopicList().get(i); - if (!EventMeshUtil.isValidRMBTopic(topic)) { - throw new Exception("invalid topic!"); - } - topicList.add(topic); + SubscriptionItem item = subscriptionInfo.getTopicList().get(i); + subscriptionItems.add(item); } synchronized (session) { - session.subscribe(topicList); - messageLogger.info("SubscribeTask succeed|user={}|topics={}", session.getClient(), topicList); + session.subscribe(subscriptionItems); + messageLogger.info("SubscribeTask succeed|user={}|topics={}", session.getClient(), subscriptionItems); } msg.setHeader(new Header(Command.SUBSCRIBE_RESPONSE, OPStatus.SUCCESS.getCode(), OPStatus.SUCCESS.getDesc(), pkg.getHeader() .getSeq())); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/UnSubscribeTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/UnSubscribeTask.java index 3a338edcd6..c35245adad 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/UnSubscribeTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/UnSubscribeTask.java @@ -19,10 +19,12 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import io.netty.channel.ChannelHandlerContext; import org.apache.commons.collections4.MapUtils; +import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.Header; import org.apache.eventmesh.common.protocol.tcp.OPStatus; @@ -46,10 +48,10 @@ public void run() { Package msg = new Package(); try { synchronized (session) { - List topics = new ArrayList(); + List topics = new ArrayList(); if (MapUtils.isNotEmpty(session.getSessionContext().subscribeTopics)) { - for (String topic : session.getSessionContext().subscribeTopics.keySet()) { - topics.add(topic); + for (Map.Entry entry : session.getSessionContext().subscribeTopics.entrySet()) { + topics.add(entry.getValue()); } session.unsubscribe(topics); messageLogger.info("UnSubscriberTask succeed|user={}|topics={}", session.getClient(), topics); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/tcp/EventMeshTcpMonitor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/tcp/EventMeshTcpMonitor.java index 64775275a0..7120218517 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/tcp/EventMeshTcpMonitor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/tcp/EventMeshTcpMonitor.java @@ -107,15 +107,14 @@ public void run() { Set topicSet = new HashSet<>(); while (sessionIterator.hasNext()) { Session session = sessionIterator.next(); - AtomicLong deliveredMsgsCount = session.getPusher().getPushContext().deliveredMsgsCount; - AtomicLong deliveredFailCount = session.getPusher().getPushContext().deliverFailMsgsCount; - AtomicLong ackedMsgsCount = session.getPusher().getPushContext().ackedMsgsCount; - int unAckMsgsCount = session.getPusher().getPushContext().getTotalUnackMsgs(); + AtomicLong deliveredMsgsCount = session.getPusher().getDeliveredMsgsCount(); + AtomicLong deliveredFailCount = session.getPusher().getDeliverFailMsgsCount(); + int unAckMsgsCount = session.getPusher().getTotalUnackMsgs(); int sendTopics = session.getSessionContext().sendTopics.size(); int subscribeTopics = session.getSessionContext().subscribeTopics.size(); - tcpLogger.info("session|deliveredFailCount={}|deliveredMsgsCount={}|ackedMsgsCount={}|unAckMsgsCount={}|sendTopics={}|subscribeTopics={}|user={}", - deliveredFailCount.longValue(), deliveredMsgsCount.longValue(), ackedMsgsCount.longValue(), + tcpLogger.info("session|deliveredFailCount={}|deliveredMsgsCount={}|unAckMsgsCount={}|sendTopics={}|subscribeTopics={}|user={}", + deliveredFailCount.longValue(), deliveredMsgsCount.longValue(), unAckMsgsCount, sendTopics, subscribeTopics, session.getClient()); topicSet.addAll(session.getSessionContext().subscribeTopics.keySet()); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/EventMeshUtil.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/EventMeshUtil.java index 3814fb7de5..eca44b9ee6 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/EventMeshUtil.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/EventMeshUtil.java @@ -60,117 +60,23 @@ public static String buildPushMsgSeqNo() { return StringUtils.rightPad(String.valueOf(System.currentTimeMillis()), 6) + String.valueOf(RandomStringUtils.randomNumeric(4)); } - public static String buildMeshClientID(String clientGroup, String meshRegion, String meshCluster) { + public static String buildMeshClientID(String clientGroup, String meshCluster) { return StringUtils.trim(clientGroup) - + "-" + StringUtils.trim(meshRegion) + "(" + StringUtils.trim(meshCluster) + ")" + + "(" + StringUtils.trim(meshCluster) + ")" + "-" + EventMeshVersion.getCurrentVersionDesc() + "-" + ThreadUtil.getPID(); } - public static String buildMeshTcpClientID(String clientSysId, String clientDcn, String purpose, String meshCluster) { + public static String buildMeshTcpClientID(String clientSysId, String purpose, String meshCluster) { return StringUtils.trim(clientSysId) - + "-" + StringUtils.trim(clientDcn) + "-" + StringUtils.trim(purpose) + "-" + StringUtils.trim(meshCluster) + "-" + EventMeshVersion.getCurrentVersionDesc() + "-" + ThreadUtil.getPID(); } - public static String buildMeshTcpRRReplyerProducerGroup() { - return "EventMesh-Tcp-RRReplyer"; - } - - public static String buildMeshTcpRRReplyerClientID(String meshSysId, String meshRegion, String meshDcn, String meshCluster) { - return meshSysId - + "-" + StringUtils.trim(meshRegion) - + "-" + StringUtils.trim(meshDcn) - + "-" + StringUtils.trim(meshCluster) - + "-" + EventMeshVersion.getCurrentVersionDesc() - + "-" + ThreadUtil.getPID() - + "-RRReplyer"; - //return EventMeshVersion.getCurrentVersionDesc() + "-" + ThreadUtil.getPID() + "(" + meshConfiguration.meshCluster + ")"; - } - - public static String buildBroadcastClientConsumerGroup(String systemId, String dcn) { - return EventMeshConstants.CONSUMER_GROUP_NAME_PREFIX + EventMeshConstants.BROADCAST_PREFIX + systemId + "-" + dcn; - } - - public static String buildPersistentClientConsumerGroup(String systemId, String dcn) { - return EventMeshConstants.CONSUMER_GROUP_NAME_PREFIX + systemId + "-" + dcn; - } - - public static String buildClientGroup(String systemId, String dcn) { - return systemId + "-" + dcn; - } - - public static String buildClientProducerGroup(String systemId, String dcn) { - return EventMeshConstants.PRODUCER_GROUP_NAME_PREFIX + systemId + "-" + dcn; - } - - public static String buildCCAddr(String str) { - return str + "/namesrvAddr"; - } - - public static String buildCCAddr(String str, String idc) { - return str + "/namesrvAddr/" + idc; - } - - public static boolean isValidRMBTopic(String topic) { - if (StringUtils.isEmpty(topic) || !StringUtils.contains(topic, "-")) { - return false; - } - - String[] args = StringUtils.split(topic, "-"); - if (ArrayUtils.getLength(args) != 5) { - return false; - } - - String s0e = args[1]; - if (!StringUtils.equalsIgnoreCase("s", s0e) && !StringUtils.equalsIgnoreCase("e", s0e)) { - return false; - } - - String service = args[2]; - if (!StringUtils.isNumeric(service)) { - return false; - } - - return true; - } - - public static String getServiceIDStr(String topic) { - if (!isValidRMBTopic(topic)) { - return ""; - } - - String[] args = StringUtils.split(topic, "-"); - return args[2]; - } - - public static String getPidStr(String topic) { - if (!isValidRMBTopic(topic)) { - return ""; - } - - String[] args = StringUtils.split(topic, "-"); - return args[3]; - } - - public static boolean isService(String topic) { - String serviceStr = getServiceIDStr(topic); - if (StringUtils.isEmpty(serviceStr)) { - return false; - } - return "0".equals(StringUtils.substring(serviceStr, 3, 4)); - } - - public static boolean isBroadcast(String topic) { - String serviceStr = getServiceIDStr(topic); - if (StringUtils.isEmpty(serviceStr)) { - return false; - } - String[] args = StringUtils.split(topic, "-"); - return "3".equals(StringUtils.substring(args[2], 3, 4)) || "4".equals(StringUtils.substring(args[2], 3, 4)); + public static String buildClientGroup(String systemId) { + return systemId; } /** @@ -420,7 +326,7 @@ public static String buildUserAgentClientId(UserAgent client) { } StringBuilder sb = new StringBuilder(); sb.append(client.getSubsystem()).append("-") - .append(client.getDcn()).append("-") + .append("-") .append(client.getPid()).append("-") .append(client.getHost()).append(":").append(client.getPort()); return sb.toString(); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/MessageClientIDSetter.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/MessageClientIDSetter.java deleted file mode 100644 index 81fa18372e..0000000000 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/MessageClientIDSetter.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Licensed to Apache Software Foundation (ASF) under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Apache Software Foundation (ASF) licenses this file to you 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. - */ -package org.apache.eventmesh.runtime.util; - -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; -import java.net.Inet4Address; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.nio.ByteBuffer; -import java.util.Calendar; -import java.util.Enumeration; -import java.util.concurrent.atomic.AtomicInteger; - -import io.openmessaging.api.Message; - -public class MessageClientIDSetter { - - public static final String PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX = "UNIQ_KEY"; - private static final String TOPIC_KEY_SPLITTER = "#"; - private static final int LEN; - private static final String FIX_STRING; - private static final AtomicInteger COUNTER; - private static long startTime; - private static long nextStartTime; - - final static char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray(); - - static { - LEN = 4 + 2 + 4 + 4 + 2; - ByteBuffer tempBuffer = ByteBuffer.allocate(10); - tempBuffer.position(2); - tempBuffer.putInt(getPid()); - tempBuffer.position(0); - try { - tempBuffer.put(getIP()); - } catch (Exception e) { - tempBuffer.put(createFakeIP()); - } - tempBuffer.position(6); - tempBuffer.putInt(MessageClientIDSetter.class.getClassLoader().hashCode()); - FIX_STRING = bytes2string(tempBuffer.array()); - setStartTime(System.currentTimeMillis()); - COUNTER = new AtomicInteger(0); - } - - public static void setUniqID(final Message msg) { - if (msg.getUserProperties(PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX) == null) { - msg.getUserProperties().put(PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX, createUniqID()); - } - } - - public static String createUniqID() { - StringBuilder sb = new StringBuilder(LEN * 2); - sb.append(FIX_STRING); - sb.append(bytes2string(createUniqIDBuffer())); - return sb.toString(); - } - - public static String bytes2string(byte[] src) { - char[] hexChars = new char[src.length * 2]; - for (int j = 0; j < src.length; j++) { - int v = src[j] & 0xFF; - hexChars[j * 2] = HEX_ARRAY[v >>> 4]; - hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F]; - } - return new String(hexChars); - } - - private synchronized static void setStartTime(long millis) { - Calendar cal = Calendar.getInstance(); - cal.setTimeInMillis(millis); - cal.set(Calendar.DAY_OF_MONTH, 1); - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MILLISECOND, 0); - startTime = cal.getTimeInMillis(); - cal.add(Calendar.MONTH, 1); - nextStartTime = cal.getTimeInMillis(); - } - - private static byte[] createUniqIDBuffer() { - ByteBuffer buffer = ByteBuffer.allocate(4 + 2); - long current = System.currentTimeMillis(); - if (current >= nextStartTime) { - setStartTime(current); - } - buffer.position(0); - buffer.putInt((int) (System.currentTimeMillis() - startTime)); - buffer.putShort((short) COUNTER.getAndIncrement()); - return buffer.array(); - } - - public static byte[] createFakeIP() { - ByteBuffer bb = ByteBuffer.allocate(8); - bb.putLong(System.currentTimeMillis()); - bb.position(4); - byte[] fakeIP = new byte[4]; - bb.get(fakeIP); - return fakeIP; - } - - public static int getPid() { - RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); - String name = runtime.getName(); // format: "pid@hostname" - try { - return Integer.parseInt(name.substring(0, name.indexOf('@'))); - } catch (Exception e) { - return -1; - } - } - - public static byte[] getIP() { - try { - Enumeration allNetInterfaces = NetworkInterface.getNetworkInterfaces(); - InetAddress ip = null; - byte[] internalIP = null; - while (allNetInterfaces.hasMoreElements()) { - NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement(); - Enumeration addresses = netInterface.getInetAddresses(); - while (addresses.hasMoreElements()) { - ip = (InetAddress) addresses.nextElement(); - if (ip != null && ip instanceof Inet4Address) { - byte[] ipByte = ip.getAddress(); - if (ipByte.length == 4) { - if (ipCheck(ipByte)) { - if (!isInternalIP(ipByte)) { - return ipByte; - } else if (internalIP == null) { - internalIP = ipByte; - } - } - } - } - } - } - if (internalIP != null) { - return internalIP; - } else { - throw new RuntimeException("Can not get local ip"); - } - } catch (Exception e) { - throw new RuntimeException("Can not get local ip", e); - } - } - - public static boolean isInternalIP(byte[] ip) { - if (ip.length != 4) { - throw new RuntimeException("illegal ipv4 bytes"); - } - - //10.0.0.0~10.255.255.255 - //172.16.0.0~172.31.255.255 - //192.168.0.0~192.168.255.255 - if (ip[0] == (byte) 10) { - - return true; - } else if (ip[0] == (byte) 172) { - if (ip[1] >= (byte) 16 && ip[1] <= (byte) 31) { - return true; - } - } else if (ip[0] == (byte) 192) { - if (ip[1] == (byte) 168) { - return true; - } - } - return false; - } - - private static boolean ipCheck(byte[] ip) { - if (ip.length != 4) { - throw new RuntimeException("illegal ipv4 bytes"); - } - -// if (ip[0] == (byte)30 && ip[1] == (byte)10 && ip[2] == (byte)163 && ip[3] == (byte)120) { -// } - - if (ip[0] >= (byte) 1 && ip[0] <= (byte) 126) { - if (ip[1] == (byte) 1 && ip[2] == (byte) 1 && ip[3] == (byte) 1) { - return false; - } - if (ip[1] == (byte) 0 && ip[2] == (byte) 0 && ip[3] == (byte) 0) { - return false; - } - return true; - } else if (ip[0] >= (byte) 128 && ip[0] <= (byte) 191) { - if (ip[2] == (byte) 1 && ip[3] == (byte) 1) { - return false; - } - if (ip[2] == (byte) 0 && ip[3] == (byte) 0) { - return false; - } - return true; - } else if (ip[0] >= (byte) 192 && ip[0] <= (byte) 223) { - if (ip[3] == (byte) 1) { - return false; - } - if (ip[3] == (byte) 0) { - return false; - } - return true; - } - return false; - } - -} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/NetUtils.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/NetUtils.java new file mode 100644 index 0000000000..a2563bce3b --- /dev/null +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/NetUtils.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.runtime.util; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.UnsupportedEncodingException; +import java.net.InetSocketAddress; +import java.net.URLDecoder; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class NetUtils { + + private static final Logger logger = LoggerFactory.getLogger(NetUtils.class); + + /** + * Transform the url form string to Map + * + * @param formData + * @return + */ + public static Map formData2Dic(String formData) { + Map result = new HashMap<>(); + if (formData == null || formData.trim().length() == 0) { + return result; + } + final String[] items = formData.split("&"); + Arrays.stream(items).forEach(item -> { + final String[] keyAndVal = item.split("="); + if (keyAndVal.length == 2) { + try { + final String key = URLDecoder.decode(keyAndVal[0], "utf8"); + final String val = URLDecoder.decode(keyAndVal[1], "utf8"); + result.put(key, val); + } catch (UnsupportedEncodingException e) { + logger.warn("formData2Dic:param decode failed...", e); + } + } + }); + return result; + } + + public static String addressToString(List clients) { + if (clients.isEmpty()) { + return "no session had been closed"; + } + StringBuilder sb = new StringBuilder(); + for (InetSocketAddress addr : clients) { + sb.append(addr).append("|"); + } + return sb.toString(); + } +} diff --git a/eventmesh-runtime/src/test/java/client/EventMeshClient.java b/eventmesh-runtime/src/test/java/client/EventMeshClient.java index ce4a13ed4a..547bf61f6b 100644 --- a/eventmesh-runtime/src/test/java/client/EventMeshClient.java +++ b/eventmesh-runtime/src/test/java/client/EventMeshClient.java @@ -17,9 +17,11 @@ package client; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.Package; import client.hook.ReceiveMsgHook; +import org.apache.eventmesh.common.protocol.SubscriptionMode; public interface EventMeshClient { @@ -37,13 +39,9 @@ public interface EventMeshClient { Package listen() throws Exception; - Package justSubscribe(String serviceId, String scenario, String dcn) throws Exception; + Package justSubscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) throws Exception; - Package justUnsubscribe(String serviceId, String scenario, String dcn) throws Exception; - - Package justSubscribe(String topic) throws Exception; - - Package justUnsubscribe(String topic) throws Exception; + Package justUnsubscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) throws Exception; void registerPubBusiHandler(ReceiveMsgHook handler) throws Exception; diff --git a/eventmesh-runtime/src/test/java/client/SubClient.java b/eventmesh-runtime/src/test/java/client/SubClient.java index dff635ac0d..e591ea67e3 100644 --- a/eventmesh-runtime/src/test/java/client/SubClient.java +++ b/eventmesh-runtime/src/test/java/client/SubClient.java @@ -17,7 +17,9 @@ package client; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import client.hook.ReceiveMsgHook; @@ -32,13 +34,9 @@ public interface SubClient { void reconnect() throws Exception; - Package justSubscribe(String serviceId, String scenario, String dcn) throws Exception; + Package justSubscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) throws Exception; - Package justSubscribe(String topic) throws Exception; - - Package justUnsubscribe(String serviceId, String scenario, String dcn) throws Exception; - - Package justUnsubscribe(String topic) throws Exception; + Package justUnsubscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) throws Exception; Package listen() throws Exception; diff --git a/eventmesh-runtime/src/test/java/client/common/ClientConstants.java b/eventmesh-runtime/src/test/java/client/common/ClientConstants.java index 6c34774e17..3a9ec48ee6 100644 --- a/eventmesh-runtime/src/test/java/client/common/ClientConstants.java +++ b/eventmesh-runtime/src/test/java/client/common/ClientConstants.java @@ -27,7 +27,7 @@ public interface ClientConstants { long DEFAULT_TIMEOUT_IN_MILLISECONDS = 3000; - String SYNC_TOPIC = "FT0-s-80000000-01-0"; - String ASYNC_TOPIC = "FT0-e-80010000-01-1"; - String BROADCAST_TOPIC = "FT0-e-80030000-01-3"; + String SYNC_TOPIC = "TEST-TOPIC-TCP-SYNC"; + String ASYNC_TOPIC = "TEST-TOPIC-TCP-ASYNC"; + String BROADCAST_TOPIC = "TEST-TOPIC-TCP-BROADCAST"; } diff --git a/eventmesh-runtime/src/test/java/client/common/MessageUtils.java b/eventmesh-runtime/src/test/java/client/common/MessageUtils.java index 0eb313ed3e..2be91670cd 100644 --- a/eventmesh-runtime/src/test/java/client/common/MessageUtils.java +++ b/eventmesh-runtime/src/test/java/client/common/MessageUtils.java @@ -21,12 +21,12 @@ import java.util.List; import java.util.concurrent.ThreadLocalRandom; -import org.apache.eventmesh.common.protocol.tcp.Command; -import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; -import org.apache.eventmesh.common.protocol.tcp.Header; -import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.Subscription; -import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.SubscriptionMode; +import org.apache.eventmesh.common.protocol.tcp.*; +import org.apache.eventmesh.common.protocol.tcp.Package; public class MessageUtils { public static int seqLength = 10; @@ -63,10 +63,10 @@ public static Package subscribe() { return msg; } - public static Package subscribe(String topic) { + public static Package subscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) { Package msg = new Package(); msg.setHeader(new Header(Command.SUBSCRIBE_REQUEST, 0, null, generateRandomString(seqLength))); - msg.setBody(generateSubscription(topic)); + msg.setBody(generateSubscription(topic, subscriptionMode, subcriptionType)); return msg; } @@ -76,10 +76,10 @@ public static Package unsubscribe() { return msg; } - public static Package unsubscribe(String topic) { + public static Package unsubscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) { Package msg = new Package(); msg.setHeader(new Header(Command.UNSUBSCRIBE_REQUEST, 0, null, generateRandomString(seqLength))); - msg.setBody(generateSubscription(topic)); + msg.setBody(generateSubscription(topic, subscriptionMode, subcriptionType)); return msg; } @@ -141,7 +141,6 @@ public static Package responseToClientAck(Package in) { public static UserAgent generatePubClient() { UserAgent user = new UserAgent(); - user.setDcn("AC0"); user.setHost("127.0.0.1"); user.setPassword(generateRandomString(8)); user.setUsername("PU4283"); @@ -156,7 +155,6 @@ public static UserAgent generatePubClient() { public static UserAgent generateSubServer() { UserAgent user = new UserAgent(); - user.setDcn("FT0"); user.setHost("127.0.0.1"); user.setPassword(generateRandomString(8)); user.setUsername("PU4283"); @@ -170,20 +168,20 @@ public static UserAgent generateSubServer() { public static Subscription generateSubscription() { Subscription subscription = new Subscription(); - List topicList = new ArrayList<>(); - topicList.add("FT0-s-80000000-01-0"); - topicList.add("FT0-s-80000000-02-0"); - topicList.add("FT0-s-80000000-03-0"); - topicList.add("FT0-s-80000000-04-0"); - subscription.setTopicList(topicList); + List subscriptionItems = new ArrayList<>(); + subscriptionItems.add(new SubscriptionItem("TEST-TOPIC-TCP-SYNC", SubscriptionMode.CLUSTERING, SubcriptionType.SYNC)); + subscriptionItems.add(new SubscriptionItem("TEST-TOPIC-TCP-SYNC2", SubscriptionMode.CLUSTERING, SubcriptionType.SYNC)); + subscriptionItems.add(new SubscriptionItem("TEST-TOPIC-TCP-SYNC3", SubscriptionMode.CLUSTERING, SubcriptionType.SYNC)); + subscriptionItems.add(new SubscriptionItem("TEST-TOPIC-TCP-SYNC4", SubscriptionMode.CLUSTERING, SubcriptionType.SYNC)); + subscription.setTopicList(subscriptionItems); return subscription; } - public static Subscription generateSubscription(String topic) { + public static Subscription generateSubscription(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) { Subscription subscription = new Subscription(); - List topicList = new ArrayList<>(); - topicList.add(topic); - subscription.setTopicList(topicList); + List subscriptionItems = new ArrayList<>(); + subscriptionItems.add(new SubscriptionItem(topic, subscriptionMode, subcriptionType)); + subscription.setTopicList(subscriptionItems); return subscription; } diff --git a/eventmesh-runtime/src/test/java/client/common/UserAgentUtils.java b/eventmesh-runtime/src/test/java/client/common/UserAgentUtils.java index eff23f1a9c..fdcdff43eb 100644 --- a/eventmesh-runtime/src/test/java/client/common/UserAgentUtils.java +++ b/eventmesh-runtime/src/test/java/client/common/UserAgentUtils.java @@ -26,7 +26,6 @@ public class UserAgentUtils { public static UserAgent createPubUserAgent() { UserAgent userAgent = new UserAgent(); userAgent.setSubsystem("5023"); - userAgent.setDcn("AC0"); userAgent.setPid(32893); userAgent.setVersion("2.0.11"); userAgent.setIdc("FT"); @@ -43,7 +42,6 @@ public static UserAgent createPubUserAgent() { public static UserAgent createUserAgent() { UserAgent userAgent = new UserAgent(); userAgent.setSubsystem("5123"); - userAgent.setDcn("WAC"); // userAgent.setPid(UtilAll.getPid()); // userAgent.setHost(RemotingUtil.getLocalAddress()); userAgent.setVersion("2.0.8"); @@ -55,7 +53,6 @@ public static UserAgent createUserAgent() { public static UserAgent createSubUserAgent() { UserAgent userAgent = new UserAgent(); userAgent.setSubsystem("5243"); - userAgent.setDcn("WAC"); // userAgent.setPid(UtilAll.getPid()); // userAgent.setHost(RemotingUtil.getLocalAddress()); userAgent.setPort(8888); diff --git a/eventmesh-runtime/src/test/java/client/impl/EventMeshClientImpl.java b/eventmesh-runtime/src/test/java/client/impl/EventMeshClientImpl.java index 5f58c1e54f..3913bcdd01 100644 --- a/eventmesh-runtime/src/test/java/client/impl/EventMeshClientImpl.java +++ b/eventmesh-runtime/src/test/java/client/impl/EventMeshClientImpl.java @@ -17,7 +17,9 @@ package client.impl; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import client.EventMeshClient; @@ -76,26 +78,19 @@ public void heartbeat() throws Exception { this.subClient.heartbeat(); } - public Package justSubscribe(String serviceId, String scenario, String dcn) throws Exception { - return this.subClient.justSubscribe(serviceId, scenario, dcn); - } public Package listen() throws Exception { return this.subClient.listen(); } - public Package justUnsubscribe(String serviceId, String scenario, String dcn) throws Exception { - return this.subClient.justUnsubscribe(serviceId, scenario, dcn); - } - @Override - public Package justSubscribe(String topic) throws Exception { - return this.subClient.justSubscribe(topic); + public Package justSubscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) throws Exception { + return this.subClient.justSubscribe(topic, subscriptionMode, subcriptionType); } @Override - public Package justUnsubscribe(String topic) throws Exception { - return this.subClient.justUnsubscribe(topic); + public Package justUnsubscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) throws Exception { + return this.subClient.justUnsubscribe(topic, subscriptionMode, subcriptionType); } diff --git a/eventmesh-runtime/src/test/java/client/impl/SubClientImpl.java b/eventmesh-runtime/src/test/java/client/impl/SubClientImpl.java index 3a61b48683..e77171558c 100644 --- a/eventmesh-runtime/src/test/java/client/impl/SubClientImpl.java +++ b/eventmesh-runtime/src/test/java/client/impl/SubClientImpl.java @@ -27,10 +27,11 @@ import io.netty.channel.SimpleChannelInboundHandler; import org.apache.commons.collections4.CollectionUtils; -import org.apache.eventmesh.common.protocol.tcp.Command; -import org.apache.eventmesh.common.protocol.tcp.OPStatus; +import org.apache.eventmesh.common.protocol.SubcriptionType; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.SubscriptionMode; +import org.apache.eventmesh.common.protocol.tcp.*; import org.apache.eventmesh.common.protocol.tcp.Package; -import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.junit.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,7 +51,7 @@ public class SubClientImpl extends TCPClient implements SubClient { private ReceiveMsgHook callback; - private List topics = new ArrayList(); + private List subscriptionItems = new ArrayList(); private ScheduledFuture task; @@ -72,9 +73,9 @@ public void init() throws Exception { public void reconnect() throws Exception { super.reconnect(); hello(); - if (!CollectionUtils.isEmpty(topics)) { - for (String topic : topics) { - Package request = MessageUtils.subscribe(topic); + if (!CollectionUtils.isEmpty(subscriptionItems)) { + for (SubscriptionItem item : subscriptionItems) { + Package request = MessageUtils.subscribe(item.getTopic(), item.getMode(), item.getType()); this.dispatcher(request, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); } } @@ -117,14 +118,9 @@ private void hello() throws Exception { this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); } - public Package justSubscribe(String serviceId, String scenario, String dcn) throws Exception { - Package msg = MessageUtils.subscribe(); - return this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); - } - - public Package justSubscribe(String topic) throws Exception { - topics.add(topic); - Package msg = MessageUtils.subscribe(topic); + public Package justSubscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) throws Exception { + subscriptionItems.add(new SubscriptionItem(topic, subscriptionMode, subcriptionType)); + Package msg = MessageUtils.subscribe(topic, subscriptionMode, subcriptionType); return this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); } @@ -144,14 +140,9 @@ public Package listen() throws Exception { // this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); // } - public Package justUnsubscribe(String topic) throws Exception { - topics.remove(topic); - Package msg = MessageUtils.unsubscribe(topic); - return this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); - } - - public Package justUnsubscribe(String serviceId, String scenario, String dcn) throws Exception { - Package msg = MessageUtils.unsubscribe(); + public Package justUnsubscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) throws Exception { + subscriptionItems.remove(topic); + Package msg = MessageUtils.unsubscribe(topic, subscriptionMode, subcriptionType); return this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); } diff --git a/eventmesh-runtime/src/test/java/demo/AsyncSubClient.java b/eventmesh-runtime/src/test/java/demo/AsyncSubClient.java index eb55d0ec7a..fc479ca75e 100644 --- a/eventmesh-runtime/src/test/java/demo/AsyncSubClient.java +++ b/eventmesh-runtime/src/test/java/demo/AsyncSubClient.java @@ -19,6 +19,7 @@ import io.netty.channel.ChannelHandlerContext; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Package; @@ -26,13 +27,14 @@ import client.common.MessageUtils; import client.hook.ReceiveMsgHook; import client.impl.SubClientImpl; +import org.apache.eventmesh.common.protocol.SubscriptionMode; public class AsyncSubClient { public static void main(String[] args) throws Exception { SubClientImpl client = new SubClientImpl("127.0.0.1", 10002, MessageUtils.generateSubServer()); client.init(); client.heartbeat(); - client.justSubscribe(ClientConstants.ASYNC_TOPIC); + client.justSubscribe(ClientConstants.ASYNC_TOPIC, SubscriptionMode.CLUSTERING, SubcriptionType.ASYNC); client.registerBusiHandler(new ReceiveMsgHook() { @Override public void handle(Package msg, ChannelHandlerContext ctx) { diff --git a/eventmesh-runtime/src/test/java/demo/BroadCastSubClient.java b/eventmesh-runtime/src/test/java/demo/BroadCastSubClient.java index f3f29f666a..3d9385d750 100644 --- a/eventmesh-runtime/src/test/java/demo/BroadCastSubClient.java +++ b/eventmesh-runtime/src/test/java/demo/BroadCastSubClient.java @@ -19,6 +19,7 @@ import io.netty.channel.ChannelHandlerContext; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Package; @@ -27,13 +28,14 @@ import client.common.MessageUtils; import client.hook.ReceiveMsgHook; import client.impl.SubClientImpl; +import org.apache.eventmesh.common.protocol.SubscriptionMode; public class BroadCastSubClient { public static void main(String[] args) throws Exception { SubClientImpl client = new SubClientImpl("127.0.0.1", 10000, MessageUtils.generateSubServer()); client.init(); client.heartbeat(); - client.justSubscribe(ClientConstants.BROADCAST_TOPIC); + client.justSubscribe(ClientConstants.BROADCAST_TOPIC, SubscriptionMode.BROADCASTING, SubcriptionType.ASYNC); client.registerBusiHandler(new ReceiveMsgHook() { @Override public void handle(Package msg, ChannelHandlerContext ctx) { diff --git a/eventmesh-runtime/src/test/java/demo/CCSubClient.java b/eventmesh-runtime/src/test/java/demo/CCSubClient.java index d415743cf3..c72597410b 100644 --- a/eventmesh-runtime/src/test/java/demo/CCSubClient.java +++ b/eventmesh-runtime/src/test/java/demo/CCSubClient.java @@ -19,6 +19,7 @@ import io.netty.channel.ChannelHandlerContext; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.Package; @@ -26,6 +27,7 @@ import client.common.UserAgentUtils; import client.hook.ReceiveMsgHook; import client.impl.SubClientImpl; +import org.apache.eventmesh.common.protocol.SubscriptionMode; public class CCSubClient { @@ -34,7 +36,7 @@ public static void main(String[] args) throws Exception { subClient.init(); subClient.heartbeat(); subClient.listen(); - subClient.justSubscribe("FT0-s-80000000-01-0"); + subClient.justSubscribe("TEST-TOPIC-TCP-SYNC", SubscriptionMode.CLUSTERING, SubcriptionType.SYNC); subClient.registerBusiHandler(new ReceiveMsgHook() { @Override public void handle(Package msg, ChannelHandlerContext ctx) { diff --git a/eventmesh-runtime/src/test/java/demo/CClientDemo.java b/eventmesh-runtime/src/test/java/demo/CClientDemo.java index 590aa3fe2c..a0ade78c96 100644 --- a/eventmesh-runtime/src/test/java/demo/CClientDemo.java +++ b/eventmesh-runtime/src/test/java/demo/CClientDemo.java @@ -19,8 +19,10 @@ import io.netty.channel.ChannelHandlerContext; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,23 +37,23 @@ public class CClientDemo { public static Logger logger = LoggerFactory.getLogger(CClientDemo.class); - private static final String SYNC_TOPIC = "FT0-s-80000000-01-0"; - private static final String ASYNC_TOPIC = "FT0-e-80010000-01-1"; - private static final String BROADCAST_TOPIC = "FT0-e-80030000-01-3"; + private static final String SYNC_TOPIC = "TEST-TOPIC-TCP-SYNC"; + private static final String ASYNC_TOPIC = "TEST-TOPIC-TCP-ASYNC"; + private static final String BROADCAST_TOPIC = "TEST-TOPIC-TCP-BROADCAST"; public static void main(String[] args) throws Exception { EventMeshClientImpl client = new EventMeshClientImpl("127.0.0.1", 10000); client.init(); client.heartbeat(); - client.justSubscribe(ASYNC_TOPIC); - client.justSubscribe(BROADCAST_TOPIC); + client.justSubscribe(ASYNC_TOPIC, SubscriptionMode.CLUSTERING, SubcriptionType.ASYNC); + client.justSubscribe(BROADCAST_TOPIC, SubscriptionMode.BROADCASTING, SubcriptionType.ASYNC); client.listen(); // for (int i = 0; i < 10000; i++) { // Package rr = null; // AccessMessage rrMessage = null; // try { -// rr = client.rr(MessageUtils.rrMesssage("FT0-s-80000000-01-0"), 3000); +// rr = client.rr(MessageUtils.rrMesssage("TEST-TOPIC-TCP-SYNC"), 3000); // Thread.sleep(100); // //rrMessage = (AccessMessage) rr.getBody(); // System.err.println( "rr-reply-------------------------------------------------" + rr.toString()); @@ -70,7 +72,7 @@ public void handle(Package msg, ChannelHandlerContext ctx) { for (int i = 0; i < 10000; i++) { // ThreadUtil.randomSleep(0,200); //广播消息 - client.broadcast(MessageUtils.broadcastMessage("FT0-e-80030000-01-3", i), 5000); + client.broadcast(MessageUtils.broadcastMessage("TEST-TOPIC-TCP-BROADCAST", i), 5000); //异步消息 client.publish(MessageUtils.asyncMessage(ASYNC_TOPIC, i), 5000); } diff --git a/eventmesh-runtime/src/test/java/demo/SyncPubClient.java b/eventmesh-runtime/src/test/java/demo/SyncPubClient.java index 18a032fbc5..f7b5b72fe8 100644 --- a/eventmesh-runtime/src/test/java/demo/SyncPubClient.java +++ b/eventmesh-runtime/src/test/java/demo/SyncPubClient.java @@ -31,7 +31,7 @@ public static void main(String[] args) throws Exception { pubClient.heartbeat(); for (int i = 0; i < 100; i++) { - Package rr = pubClient.rr(MessageUtils.rrMesssage("FT0-s-80000000-01-0", i), 3000); + Package rr = pubClient.rr(MessageUtils.rrMesssage("TEST-TOPIC-TCP-SYNC", i), 3000); if (rr.getBody() instanceof EventMeshMessage) { String body = ((EventMeshMessage) rr.getBody()).getBody(); System.err.println("rrMessage: " + body + " " + "rr-reply-------------------------------------------------" + rr.toString()); diff --git a/eventmesh-runtime/src/test/java/demo/SyncSubClient.java b/eventmesh-runtime/src/test/java/demo/SyncSubClient.java index 10e13c4ae8..9bc11415a3 100644 --- a/eventmesh-runtime/src/test/java/demo/SyncSubClient.java +++ b/eventmesh-runtime/src/test/java/demo/SyncSubClient.java @@ -19,6 +19,7 @@ import io.netty.channel.ChannelHandlerContext; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.Package; @@ -26,13 +27,14 @@ import client.common.MessageUtils; import client.hook.ReceiveMsgHook; import client.impl.SubClientImpl; +import org.apache.eventmesh.common.protocol.SubscriptionMode; public class SyncSubClient { public static void main(String[] args) throws Exception { SubClientImpl client = new SubClientImpl("127.0.0.1", 10000, MessageUtils.generateSubServer()); client.init(); client.heartbeat(); - client.justSubscribe(ClientConstants.SYNC_TOPIC); + client.justSubscribe(ClientConstants.SYNC_TOPIC, SubscriptionMode.CLUSTERING, SubcriptionType.SYNC); client.registerBusiHandler(new ReceiveMsgHook() { @Override public void handle(Package msg, ChannelHandlerContext ctx) { diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandlerTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandlerTest.java new file mode 100644 index 0000000000..c28a460d7a --- /dev/null +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandlerTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.eventmesh.runtime.admin.handler; + +import com.sun.net.httpserver.HttpExchange; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.powermock.api.mockito.PowerMockito; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.net.URI; + +public class RedirectClientByIpPortHandlerTest { + + private RedirectClientByIpPortHandler redirectClientByIpPortHandler; + + @Before + public void init() { + EventMeshTCPServer mockServer = PowerMockito.mock(EventMeshTCPServer.class); + redirectClientByIpPortHandler = new RedirectClientByIpPortHandler(mockServer); + } + + @Test + public void testHandleParamIllegal() throws IOException { + OutputStream outputStream = new ByteArrayOutputStream(); + URI uri = URI.create("ip=127.0.0.1&port=1234&desteventMeshIp=127.0.0.1&desteventMeshPort="); + + HttpExchange mockExchange = PowerMockito.mock(HttpExchange.class); + PowerMockito.when(mockExchange.getResponseBody()).thenReturn(outputStream); + PowerMockito.when(mockExchange.getRequestURI()).thenReturn(uri); + + redirectClientByIpPortHandler.handle(mockExchange); + + String response = outputStream.toString(); + Assert.assertEquals("params illegal!", response); + + } +} \ No newline at end of file diff --git a/eventmesh-sdk-java/gradle.properties b/eventmesh-sdk-java/gradle.properties index 90227e6a29..ba5ffa736e 100644 --- a/eventmesh-sdk-java/gradle.properties +++ b/eventmesh-sdk-java/gradle.properties @@ -15,6 +15,6 @@ # limitations under the License. # group=org.apache.eventmesh -version=1.2.0 +version=1.2.0-release jdk=1.8 snapshot=false diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/AbstractLiteClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/AbstractLiteClient.java index 261fbb423c..20302af8e6 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/AbstractLiteClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/AbstractLiteClient.java @@ -17,61 +17,33 @@ package org.apache.eventmesh.client.http; -import java.util.Arrays; -import java.util.List; - -import com.google.common.collect.Lists; - -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.client.http.conf.LiteClientConfig; -import org.apache.eventmesh.common.EventMeshException; +import org.apache.eventmesh.client.http.ssl.MyX509TrustManager; +import org.apache.eventmesh.client.http.util.HttpLoadBalanceUtils; +import org.apache.eventmesh.common.loadbalance.LoadBalanceSelector; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import java.security.SecureRandom; public abstract class AbstractLiteClient { public Logger logger = LoggerFactory.getLogger(AbstractLiteClient.class); - private static CloseableHttpClient wpcli = HttpClients.createDefault(); - - public LiteClientConfig liteClientConfig; + protected LiteClientConfig liteClientConfig; - public static final String REGEX_VALIDATE_FOR_RPOXY_DEFAULT; - - static { - REGEX_VALIDATE_FOR_RPOXY_DEFAULT = "^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}:\\d{4,5};)*(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}:\\d{4,5})$"; - } - - public List eventMeshServerList = Lists.newArrayList(); + protected LoadBalanceSelector eventMeshServerSelector; public AbstractLiteClient(LiteClientConfig liteClientConfig) { this.liteClientConfig = liteClientConfig; } public void start() throws Exception { - eventMeshServerList = process(liteClientConfig.getLiteEventMeshAddr()); - if (eventMeshServerList == null || eventMeshServerList.size() < 1) { - throw new EventMeshException("liteEventMeshAddr param illegal,please check"); - } - } - - private List process(String format) { - List list = Lists.newArrayList(); - if (StringUtils.isNotBlank(format) && format.matches(REGEX_VALIDATE_FOR_RPOXY_DEFAULT)) { - - String[] serversArr = StringUtils.split(format, ";"); - if (ArrayUtils.isNotEmpty(serversArr)) { - list.addAll(Arrays.asList(serversArr)); - } - - return list; - } - - logger.error("servers is bad format, servers:{}", format); - return null; + eventMeshServerSelector = HttpLoadBalanceUtils.createEventMeshServerLoadBalanceSelector(liteClientConfig); } public LiteClientConfig getLiteClientConfig() { @@ -81,4 +53,22 @@ public LiteClientConfig getLiteClientConfig() { public void shutdown() throws Exception { logger.info("AbstractLiteClient shutdown"); } + + public CloseableHttpClient setHttpClient() throws Exception { + if (!liteClientConfig.isUseTls()) { + return HttpClients.createDefault(); + } + SSLContext sslContext = null; + try { + String protocol = System.getProperty("ssl.client.protocol", "TLSv1.2"); + TrustManager[] tm = new TrustManager[]{new MyX509TrustManager()}; + sslContext = SSLContext.getInstance(protocol); + sslContext.init(null, tm, new SecureRandom()); + return HttpClients.custom().setSSLContext(sslContext) + .setSSLHostnameVerifier(new DefaultHostnameVerifier()).build(); + } catch (Exception e) { + logger.error("Error in creating HttpClient.", e); + throw e; + } + } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/RemotingServer.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/RemotingServer.java index e85937e9ef..c24198d042 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/RemotingServer.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/RemotingServer.java @@ -258,8 +258,7 @@ protected void channelRead0(final ChannelHandlerContext ctx, HttpRequest httpReq final LiteConsumeContext eventMeshConsumeContext = new LiteConsumeContext(pushMessageRequestHeader.getEventMeshIp(), pushMessageRequestHeader.getEventMeshEnv(), pushMessageRequestHeader.getEventMeshIdc(), - pushMessageRequestHeader.getEventMeshRegion(), - pushMessageRequestHeader.getEventMeshCluster(), pushMessageRequestHeader.getEventMeshDcn()); + pushMessageRequestHeader.getEventMeshCluster()); final LiteMessage liteMessage = new LiteMessage(pushMessageRequestBody.getBizSeqNo(), pushMessageRequestBody.getUniqueId(), topic, pushMessageRequestBody.getContent()); diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/conf/LiteClientConfig.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/conf/LiteClientConfig.java index 21140b2ab8..fc5368a139 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/conf/LiteClientConfig.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/conf/LiteClientConfig.java @@ -17,21 +17,34 @@ package org.apache.eventmesh.client.http.conf; +import org.apache.eventmesh.common.loadbalance.LoadBalanceType; + public class LiteClientConfig { + /** + * The event server address list + *

+ * If it's a cluster, please use ; to split, and the address format is related to loadBalanceType. + *

+ * E.g. + *

If you use Random strategy, the format like: 127.0.0.1:10105;127.0.0.2:10105 + *

If you use weighted round robin strategy, the format like: 127.0.0.1:10105:1;127.0.0.2:10105:2 + */ private String liteEventMeshAddr = "127.0.0.1:10105"; + private LoadBalanceType loadBalanceType = LoadBalanceType.RANDOM; + private int consumeThreadCore = 2; private int consumeThreadMax = 5; private String env; - private String region; + private String consumerGroup = "DefaultConsumerGroup"; - private String idc; + private String producerGroup = "DefaultProducerGroup"; - private String dcn; + private String idc; private String ip = "127.0.0.1"; @@ -45,12 +58,21 @@ public class LiteClientConfig { private boolean useTls = false; - public int getConsumeThreadMax() { - return consumeThreadMax; + public String getLiteEventMeshAddr() { + return liteEventMeshAddr; } - public LiteClientConfig setConsumeThreadMax(int consumeThreadMax) { - this.consumeThreadMax = consumeThreadMax; + public LiteClientConfig setLiteEventMeshAddr(String liteEventMeshAddr) { + this.liteEventMeshAddr = liteEventMeshAddr; + return this; + } + + public LoadBalanceType getLoadBalanceType() { + return loadBalanceType; + } + + public LiteClientConfig setLoadBalanceType(LoadBalanceType loadBalanceType) { + this.loadBalanceType = loadBalanceType; return this; } @@ -63,21 +85,21 @@ public LiteClientConfig setConsumeThreadCore(int consumeThreadCore) { return this; } - public String getEnv() { - return env; + public int getConsumeThreadMax() { + return consumeThreadMax; } - public LiteClientConfig setEnv(String env) { - this.env = env; + public LiteClientConfig setConsumeThreadMax(int consumeThreadMax) { + this.consumeThreadMax = consumeThreadMax; return this; } - public String getRegion() { - return region; + public String getEnv() { + return env; } - public LiteClientConfig setRegion(String region) { - this.region = region; + public LiteClientConfig setEnv(String env) { + this.env = env; return this; } @@ -90,15 +112,6 @@ public LiteClientConfig setIdc(String idc) { return this; } - public String getDcn() { - return dcn; - } - - public LiteClientConfig setDcn(String dcn) { - this.dcn = dcn; - return this; - } - public String getIp() { return ip; } @@ -144,21 +157,31 @@ public LiteClientConfig setPassword(String password) { return this; } - public String getLiteEventMeshAddr() { - return liteEventMeshAddr; + public boolean isUseTls() { + return useTls; } - public LiteClientConfig setLiteEventMeshAddr(String liteEventMeshAddr) { - this.liteEventMeshAddr = liteEventMeshAddr; + public LiteClientConfig setUseTls(boolean useTls) { + this.useTls = useTls; return this; } - public boolean isUseTls() { - return useTls; + public String getConsumerGroup() { + return consumerGroup; } - public void setUseTls(boolean useTls) { - this.useTls = useTls; + public LiteClientConfig setConsumerGroup(String consumerGroup) { + this.consumerGroup = consumerGroup; + return this; + } + + public String getProducerGroup() { + return producerGroup; + } + + public LiteClientConfig setProducerGroup(String producerGroup) { + this.producerGroup = producerGroup; + return this; } @Override @@ -166,12 +189,13 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("liteClientConfig={") .append("liteEventMeshAddr=").append(liteEventMeshAddr).append(",") + .append("loadBalanceType=").append(loadBalanceType).append(",") .append("consumeThreadCore=").append(consumeThreadCore).append(",") .append("consumeThreadMax=").append(consumeThreadMax).append(",") .append("env=").append(env).append(",") - .append("region=").append(region).append(",") .append("idc=").append(idc).append(",") - .append("dcn=").append(dcn).append(",") + .append("producerGroup=").append(producerGroup).append(",") + .append("consumerGroup=").append(consumerGroup).append(",") .append("ip=").append(ip).append(",") .append("pid=").append(pid).append(",") .append("sys=").append(sys).append(",") diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/LiteConsumer.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/LiteConsumer.java index 801481a418..7841a67eaa 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/LiteConsumer.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/LiteConsumer.java @@ -18,7 +18,10 @@ package org.apache.eventmesh.client.http.consumer; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.*; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -45,13 +48,16 @@ import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.EventMeshException; import org.apache.eventmesh.common.ThreadPoolFactory; +import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.http.body.client.HeartbeatRequestBody; import org.apache.eventmesh.common.protocol.http.body.client.SubscribeRequestBody; +import org.apache.eventmesh.common.protocol.http.body.client.UnSubscribeRequestBody; import org.apache.eventmesh.common.protocol.http.common.ClientType; import org.apache.eventmesh.common.protocol.http.common.EventMeshRetCode; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.common.RequestCode; +import org.apache.eventmesh.common.protocol.tcp.Subscription; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.slf4j.Logger; @@ -65,15 +71,13 @@ public class LiteConsumer extends AbstractLiteClient { private ThreadPoolExecutor consumeExecutor; - private static CloseableHttpClient httpClient = HttpClients.createDefault(); - protected LiteClientConfig eventMeshClientConfig; - private List subscription = Lists.newArrayList(); + private List subscription = Lists.newArrayList(); private LiteMessageListener messageListener; - protected static final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(4, new EventMeshThreadFactoryImpl("TCPClientScheduler", true)); + protected final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(4, new EventMeshThreadFactoryImpl("TCPClientScheduler", true)); public LiteConsumer(LiteClientConfig liteClientConfig) throws Exception { super(liteClientConfig); @@ -110,29 +114,28 @@ public void start() throws Exception { public void shutdown() throws Exception { logger.info("LiteConsumer shutting down"); super.shutdown(); - httpClient.close(); + if (consumeExecutor != null) { + consumeExecutor.shutdown(); + } + scheduler.shutdown(); started.compareAndSet(true, false); logger.info("LiteConsumer shutdown"); } - public boolean subscribe(List topicList, String url) throws Exception { + public boolean subscribe(List topicList, String url) throws Exception { subscription.addAll(topicList); if (!started.get()) { start(); } - RequestParam heartBeatParam = generateHeartBeatRequestParam(topicList, url); RequestParam subscribeParam = generateSubscribeRequestParam(topicList, url); long startTime = System.currentTimeMillis(); String target = selectEventMesh(); String subRes = ""; - String heartRes = ""; - try { - heartRes = HttpUtil.post(httpClient, target, heartBeatParam); + + try (CloseableHttpClient httpClient = setHttpClient()){ subRes = HttpUtil.post(httpClient, target, subscribeParam); - } catch (Exception ex) { - throw new EventMeshException(ex); } if (logger.isDebugEnabled()) { @@ -149,7 +152,7 @@ public boolean subscribe(List topicList, String url) throws Exception { } - private RequestParam generateSubscribeRequestParam(List topicList, String url) { + private RequestParam generateSubscribeRequestParam(List topicList, String url) { // final LiteMessage liteMessage = new LiteMessage(); // liteMessage.setBizSeqNo(RandomStringUtils.randomNumeric(30)) // .setContent("subscribe message") @@ -157,9 +160,7 @@ private RequestParam generateSubscribeRequestParam(List topicList, Strin RequestParam requestParam = new RequestParam(HttpMethod.POST); requestParam.addHeader(ProtocolKey.REQUEST_CODE, String.valueOf(RequestCode.SUBSCRIBE.getRequestCode())) .addHeader(ProtocolKey.ClientInstanceKey.ENV, eventMeshClientConfig.getEnv()) - .addHeader(ProtocolKey.ClientInstanceKey.REGION, eventMeshClientConfig.getRegion()) .addHeader(ProtocolKey.ClientInstanceKey.IDC, eventMeshClientConfig.getIdc()) - .addHeader(ProtocolKey.ClientInstanceKey.DCN, eventMeshClientConfig.getDcn()) .addHeader(ProtocolKey.ClientInstanceKey.IP, eventMeshClientConfig.getIp()) .addHeader(ProtocolKey.ClientInstanceKey.PID, eventMeshClientConfig.getPid()) .addHeader(ProtocolKey.ClientInstanceKey.SYS, eventMeshClientConfig.getSys()) @@ -169,15 +170,16 @@ private RequestParam generateSubscribeRequestParam(List topicList, Strin .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) .setTimeout(Constants.DEFAULT_HTTP_TIME_OUT) .addBody(SubscribeRequestBody.TOPIC, JSONObject.toJSONString(topicList)) + .addBody(SubscribeRequestBody.CONSUMERGROUP, eventMeshClientConfig.getConsumerGroup()) .addBody(SubscribeRequestBody.URL, url); return requestParam; } - private RequestParam generateHeartBeatRequestParam(List topics, String url) { + private RequestParam generateHeartBeatRequestParam(List topics, String url) { List heartbeatEntities = new ArrayList<>(); - for (String topic : topics) { + for (SubscriptionItem item : topics) { HeartbeatRequestBody.HeartbeatEntity heartbeatEntity = new HeartbeatRequestBody.HeartbeatEntity(); - heartbeatEntity.topic = topic; + heartbeatEntity.topic = item.getTopic(); heartbeatEntity.url = url; heartbeatEntities.add(heartbeatEntity); } @@ -185,9 +187,7 @@ private RequestParam generateHeartBeatRequestParam(List topics, String u RequestParam requestParam = new RequestParam(HttpMethod.POST); requestParam.addHeader(ProtocolKey.REQUEST_CODE, String.valueOf(RequestCode.HEARTBEAT.getRequestCode())) .addHeader(ProtocolKey.ClientInstanceKey.ENV, eventMeshClientConfig.getEnv()) - .addHeader(ProtocolKey.ClientInstanceKey.REGION, eventMeshClientConfig.getRegion()) .addHeader(ProtocolKey.ClientInstanceKey.IDC, eventMeshClientConfig.getIdc()) - .addHeader(ProtocolKey.ClientInstanceKey.DCN, eventMeshClientConfig.getDcn()) .addHeader(ProtocolKey.ClientInstanceKey.IP, eventMeshClientConfig.getIp()) .addHeader(ProtocolKey.ClientInstanceKey.PID, eventMeshClientConfig.getPid()) .addHeader(ProtocolKey.ClientInstanceKey.SYS, eventMeshClientConfig.getSys()) @@ -197,11 +197,12 @@ private RequestParam generateHeartBeatRequestParam(List topics, String u .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) .setTimeout(Constants.DEFAULT_HTTP_TIME_OUT) .addBody(HeartbeatRequestBody.CLIENTTYPE, ClientType.SUB.name()) + .addBody(HeartbeatRequestBody.CONSUMERGROUP, eventMeshClientConfig.getConsumerGroup()) .addBody(HeartbeatRequestBody.HEARTBEATENTITIES, JSON.toJSONString(heartbeatEntities)); return requestParam; } - public void heartBeat(List topicList, String url) throws Exception { + public void heartBeat(List topicList, String url) throws Exception { scheduler.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -214,10 +215,9 @@ public void run() { long startTime = System.currentTimeMillis(); String target = selectEventMesh(); String res = ""; - try { + + try (CloseableHttpClient httpClient = setHttpClient()) { res = HttpUtil.post(httpClient, target, requestParam); - } catch (Exception ex) { - throw new EventMeshException(ex); } if (logger.isDebugEnabled()) { @@ -237,20 +237,24 @@ public void run() { }, EventMeshCommon.HEATBEAT, EventMeshCommon.HEATBEAT, TimeUnit.MILLISECONDS); } - public boolean unsubscribe(List topicList, String url) throws EventMeshException { - subscription.removeAll(topicList); - RequestParam heartBeatParam = generateHeartBeatRequestParam(topicList, url); + public boolean unsubscribe(List topicList, String url) throws Exception { + Set unSub = new HashSet<>(topicList); + Iterator itr = subscription.iterator(); + while(itr.hasNext()) { + SubscriptionItem item = itr.next(); + if (unSub.contains(item.getTopic())) { + itr.remove(); + } + } + RequestParam unSubscribeParam = generateUnSubscribeRequestParam(topicList, url); long startTime = System.currentTimeMillis(); String target = selectEventMesh(); String unSubRes = ""; - String heartRes = ""; - try { - heartRes = HttpUtil.post(httpClient, target, heartBeatParam); + + try (CloseableHttpClient httpClient = setHttpClient()) { unSubRes = HttpUtil.post(httpClient, target, unSubscribeParam); - } catch (Exception ex) { - throw new EventMeshException(ex); } if (logger.isDebugEnabled()) { @@ -270,9 +274,7 @@ private RequestParam generateUnSubscribeRequestParam(List topicList, Str RequestParam requestParam = new RequestParam(HttpMethod.POST); requestParam.addHeader(ProtocolKey.REQUEST_CODE, String.valueOf(RequestCode.UNSUBSCRIBE.getRequestCode())) .addHeader(ProtocolKey.ClientInstanceKey.ENV, eventMeshClientConfig.getEnv()) - .addHeader(ProtocolKey.ClientInstanceKey.REGION, eventMeshClientConfig.getRegion()) .addHeader(ProtocolKey.ClientInstanceKey.IDC, eventMeshClientConfig.getIdc()) - .addHeader(ProtocolKey.ClientInstanceKey.DCN, eventMeshClientConfig.getDcn()) .addHeader(ProtocolKey.ClientInstanceKey.IP, eventMeshClientConfig.getIp()) .addHeader(ProtocolKey.ClientInstanceKey.PID, eventMeshClientConfig.getPid()) .addHeader(ProtocolKey.ClientInstanceKey.SYS, eventMeshClientConfig.getSys()) @@ -281,8 +283,9 @@ private RequestParam generateUnSubscribeRequestParam(List topicList, Str .addHeader(ProtocolKey.VERSION, ProtocolVersion.V1.getVersion()) .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) .setTimeout(Constants.DEFAULT_HTTP_TIME_OUT) - .addBody(SubscribeRequestBody.TOPIC, JSONObject.toJSONString(topicList)) - .addBody(SubscribeRequestBody.URL, url); + .addBody(UnSubscribeRequestBody.TOPIC, JSONObject.toJSONString(topicList)) + .addBody(UnSubscribeRequestBody.CONSUMERGROUP, eventMeshClientConfig.getConsumerGroup()) + .addBody(UnSubscribeRequestBody.URL, url); return requestParam; } @@ -292,13 +295,10 @@ public void registerMessageListener(LiteMessageListener messageListener) throws } public String selectEventMesh() { - if (CollectionUtils.isEmpty(eventMeshServerList)) { - return null; - } if (liteClientConfig.isUseTls()) { - return Constants.HTTPS_PROTOCOL_PREFIX + eventMeshServerList.get(RandomUtils.nextInt(0, eventMeshServerList.size())); + return Constants.HTTPS_PROTOCOL_PREFIX + eventMeshServerSelector.select(); } else { - return Constants.HTTP_PROTOCOL_PREFIX + eventMeshServerList.get(RandomUtils.nextInt(0, eventMeshServerList.size())); + return Constants.HTTP_PROTOCOL_PREFIX + eventMeshServerSelector.select(); } } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/context/LiteConsumeContext.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/context/LiteConsumeContext.java index 42739ca0a9..91d84a5738 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/context/LiteConsumeContext.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/context/LiteConsumeContext.java @@ -28,26 +28,20 @@ public class LiteConsumeContext { private String eventMeshIdc; - private String eventMeshRegion; - private String eventMeshCluster; - private String eventMeshDcn; - //本地RETRY次数 private int retryTimes = 0; private long createTime = System.currentTimeMillis(); public LiteConsumeContext(String eventMeshIp, String eventMeshEnv, - String eventMeshIdc, String eventMeshRegion, - String eventMeshCluster, String eventMeshDcn) { + String eventMeshIdc, + String eventMeshCluster) { this.eventMeshIp = eventMeshIp; this.eventMeshEnv = eventMeshEnv; this.eventMeshIdc = eventMeshIdc; - this.eventMeshRegion = eventMeshRegion; this.eventMeshCluster = eventMeshCluster; - this.eventMeshDcn = eventMeshDcn; } @@ -75,14 +69,6 @@ public void setEventMeshIdc(String eventMeshIdc) { this.eventMeshIdc = eventMeshIdc; } - public String getEventMeshRegion() { - return eventMeshRegion; - } - - public void setEventMeshRegion(String eventMeshRegion) { - this.eventMeshRegion = eventMeshRegion; - } - public String getEventMeshCluster() { return eventMeshCluster; } @@ -91,14 +77,6 @@ public void setEventMeshCluster(String eventMeshCluster) { this.eventMeshCluster = eventMeshCluster; } - public String getEventMeshDcn() { - return eventMeshDcn; - } - - public void setEventMeshDcn(String eventMeshDcn) { - this.eventMeshDcn = eventMeshDcn; - } - public int getRetryTimes() { return retryTimes; } @@ -113,10 +91,8 @@ public String toString() { sb.append("liteConsumeContext={") .append("eventMeshIp=").append(eventMeshIp).append(",") .append("eventMeshEnv=").append(eventMeshEnv).append(",") - .append("eventMeshRegion=").append(eventMeshRegion).append(",") .append("eventMeshIdc=").append(eventMeshIdc).append(",") .append("eventMeshCluster=").append(eventMeshCluster).append(",") - .append("eventMeshDcn=").append(eventMeshDcn).append(",") .append("retryTimes=").append(retryTimes).append(",") .append("createTime=").append(DateFormatUtils.format(createTime, Constants.DATE_FORMAT)) .append("}"); diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/LiteProducer.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/LiteProducer.java index 3b4ecc2384..a240b95354 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/LiteProducer.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/LiteProducer.java @@ -61,13 +61,8 @@ public class LiteProducer extends AbstractLiteClient { public Logger logger = LoggerFactory.getLogger(LiteProducer.class); - private static CloseableHttpClient httpClient = HttpClients.createDefault(); - public LiteProducer(LiteClientConfig liteClientConfig) { super(liteClientConfig); - if (liteClientConfig.isUseTls()) { - setHttpClient(); - } } private AtomicBoolean started = new AtomicBoolean(Boolean.FALSE); @@ -92,7 +87,6 @@ public void shutdown() throws Exception { } logger.info("LiteProducer shutting down"); super.shutdown(); - httpClient.close(); started.compareAndSet(true, false); logger.info("LiteProducer shutdown"); } @@ -112,9 +106,7 @@ public boolean publish(LiteMessage message) throws Exception { RequestParam requestParam = new RequestParam(HttpMethod.POST); requestParam.addHeader(ProtocolKey.REQUEST_CODE, String.valueOf(RequestCode.MSG_SEND_ASYNC.getRequestCode())) .addHeader(ProtocolKey.ClientInstanceKey.ENV, liteClientConfig.getEnv()) - .addHeader(ProtocolKey.ClientInstanceKey.REGION, liteClientConfig.getRegion()) .addHeader(ProtocolKey.ClientInstanceKey.IDC, liteClientConfig.getIdc()) - .addHeader(ProtocolKey.ClientInstanceKey.DCN, liteClientConfig.getDcn()) .addHeader(ProtocolKey.ClientInstanceKey.IP, liteClientConfig.getIp()) .addHeader(ProtocolKey.ClientInstanceKey.PID, liteClientConfig.getPid()) .addHeader(ProtocolKey.ClientInstanceKey.SYS, liteClientConfig.getSys()) @@ -123,6 +115,7 @@ public boolean publish(LiteMessage message) throws Exception { .addHeader(ProtocolKey.VERSION, ProtocolVersion.V1.getVersion()) .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) .setTimeout(Constants.DEFAULT_HTTP_TIME_OUT) + .addBody(SendMessageRequestBody.PRODUCERGROUP, liteClientConfig.getProducerGroup()) .addBody(SendMessageRequestBody.TOPIC, message.getTopic()) .addBody(SendMessageRequestBody.CONTENT, message.getContent()) .addBody(SendMessageRequestBody.TTL, message.getPropKey(Constants.EVENTMESH_MESSAGE_CONST_TTL)) @@ -132,10 +125,9 @@ public boolean publish(LiteMessage message) throws Exception { long startTime = System.currentTimeMillis(); String target = selectEventMesh(); String res = ""; - try { + + try (CloseableHttpClient httpClient = setHttpClient()) { res = HttpUtil.post(httpClient, target, requestParam); - } catch (Exception ex) { - throw new EventMeshException(ex); } if (logger.isDebugEnabled()) { @@ -153,13 +145,10 @@ public boolean publish(LiteMessage message) throws Exception { } public String selectEventMesh() { - if (CollectionUtils.isEmpty(eventMeshServerList)) { - return null; - } if (liteClientConfig.isUseTls()) { - return Constants.HTTPS_PROTOCOL_PREFIX + eventMeshServerList.get(RandomUtils.nextInt(0, eventMeshServerList.size())); + return Constants.HTTPS_PROTOCOL_PREFIX + eventMeshServerSelector.select(); } else { - return Constants.HTTP_PROTOCOL_PREFIX + eventMeshServerList.get(RandomUtils.nextInt(0, eventMeshServerList.size())); + return Constants.HTTP_PROTOCOL_PREFIX + eventMeshServerSelector.select(); } } @@ -174,9 +163,7 @@ public LiteMessage request(LiteMessage message, long timeout) throws Exception { RequestParam requestParam = new RequestParam(HttpMethod.POST); requestParam.addHeader(ProtocolKey.REQUEST_CODE, String.valueOf(RequestCode.MSG_SEND_SYNC.getRequestCode())) .addHeader(ProtocolKey.ClientInstanceKey.ENV, liteClientConfig.getEnv()) - .addHeader(ProtocolKey.ClientInstanceKey.REGION, liteClientConfig.getRegion()) .addHeader(ProtocolKey.ClientInstanceKey.IDC, liteClientConfig.getIdc()) - .addHeader(ProtocolKey.ClientInstanceKey.DCN, liteClientConfig.getDcn()) .addHeader(ProtocolKey.ClientInstanceKey.IP, liteClientConfig.getIp()) .addHeader(ProtocolKey.ClientInstanceKey.PID, liteClientConfig.getPid()) .addHeader(ProtocolKey.ClientInstanceKey.SYS, liteClientConfig.getSys()) @@ -185,6 +172,7 @@ public LiteMessage request(LiteMessage message, long timeout) throws Exception { .addHeader(ProtocolKey.VERSION, ProtocolVersion.V1.getVersion()) .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) .setTimeout(timeout) + .addBody(SendMessageRequestBody.PRODUCERGROUP, liteClientConfig.getProducerGroup()) .addBody(SendMessageRequestBody.TOPIC, message.getTopic()) .addBody(SendMessageRequestBody.CONTENT, message.getContent()) .addBody(SendMessageRequestBody.TTL, String.valueOf(timeout)) @@ -194,10 +182,9 @@ public LiteMessage request(LiteMessage message, long timeout) throws Exception { long startTime = System.currentTimeMillis(); String target = selectEventMesh(); String res = ""; - try { + + try (CloseableHttpClient httpClient = setHttpClient()) { res = HttpUtil.post(httpClient, target, requestParam); - } catch (Exception ex) { - throw new EventMeshException(ex); } if (logger.isDebugEnabled()) { @@ -230,9 +217,7 @@ public void request(LiteMessage message, RRCallback rrCallback, long timeout) th RequestParam requestParam = new RequestParam(HttpMethod.POST); requestParam.addHeader(ProtocolKey.REQUEST_CODE, String.valueOf(RequestCode.MSG_SEND_SYNC.getRequestCode())) .addHeader(ProtocolKey.ClientInstanceKey.ENV, liteClientConfig.getEnv()) - .addHeader(ProtocolKey.ClientInstanceKey.REGION, liteClientConfig.getRegion()) .addHeader(ProtocolKey.ClientInstanceKey.IDC, liteClientConfig.getIdc()) - .addHeader(ProtocolKey.ClientInstanceKey.DCN, liteClientConfig.getDcn()) .addHeader(ProtocolKey.ClientInstanceKey.IP, liteClientConfig.getIp()) .addHeader(ProtocolKey.ClientInstanceKey.PID, liteClientConfig.getPid()) .addHeader(ProtocolKey.ClientInstanceKey.SYS, liteClientConfig.getSys()) @@ -241,6 +226,7 @@ public void request(LiteMessage message, RRCallback rrCallback, long timeout) th .addHeader(ProtocolKey.VERSION, ProtocolVersion.V1.getVersion()) .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) .setTimeout(timeout) + .addBody(SendMessageRequestBody.PRODUCERGROUP, liteClientConfig.getProducerGroup()) .addBody(SendMessageRequestBody.TOPIC, message.getTopic()) .addBody(SendMessageRequestBody.CONTENT, message.getContent()) .addBody(SendMessageRequestBody.TTL, String.valueOf(timeout)) @@ -249,32 +235,13 @@ public void request(LiteMessage message, RRCallback rrCallback, long timeout) th long startTime = System.currentTimeMillis(); String target = selectEventMesh(); - try { + + try (CloseableHttpClient httpClient = setHttpClient()) { HttpUtil.post(httpClient, null, target, requestParam, new RRCallbackResponseHandlerAdapter(message, rrCallback, timeout)); - } catch (Exception ex) { - throw new EventMeshException(ex); } if (logger.isDebugEnabled()) { logger.debug("publish sync message by async, target:{}, cost:{}, message:{}", target, System.currentTimeMillis() - startTime, message); } } - - public static void setHttpClient() { - SSLContext sslContext = null; - try { - String protocol = System.getProperty("ssl.client.protocol", "TLSv1.1"); - TrustManager[] tm = new TrustManager[]{new MyX509TrustManager()}; - sslContext = SSLContext.getInstance(protocol); - sslContext.init(null, tm, new SecureRandom()); - httpClient = HttpClients.custom().setSSLContext(sslContext) - .setSSLHostnameVerifier(new DefaultHostnameVerifier()).build(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtils.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtils.java new file mode 100644 index 0000000000..4350613133 --- /dev/null +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtils.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.client.http.util; + +import com.google.common.base.Splitter; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.eventmesh.client.http.conf.LiteClientConfig; +import org.apache.eventmesh.common.EventMeshException; +import org.apache.eventmesh.common.loadbalance.LoadBalanceSelector; +import org.apache.eventmesh.common.loadbalance.RandomLoadBalanceSelector; +import org.apache.eventmesh.common.loadbalance.Weight; +import org.apache.eventmesh.common.loadbalance.WeightRoundRobinLoadBalanceSelector; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +public class HttpLoadBalanceUtils { + + private static final Pattern IP_PORT_PATTERN = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}:\\d{4,5}"); + private static final Pattern IP_PORT_WEIGHT_PATTERN = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}:\\d{4,5}:\\d{1,6}"); + + public static LoadBalanceSelector createEventMeshServerLoadBalanceSelector(LiteClientConfig liteClientConfig) + throws EventMeshException { + List eventMeshAddrs = Splitter.on(";").splitToList(liteClientConfig.getLiteEventMeshAddr()); + if (CollectionUtils.isEmpty(eventMeshAddrs)) { + throw new EventMeshException("liteEventMeshAddr can not be empty"); + } + + LoadBalanceSelector eventMeshServerSelector = null; + switch (liteClientConfig.getLoadBalanceType()) { + case RANDOM: + List eventMeshAddrList = new ArrayList<>(); + for (String eventMeshAddr : eventMeshAddrs) { + if (!IP_PORT_PATTERN.matcher(eventMeshAddr).matches()) { + throw new EventMeshException( + String.format("liteEventMeshAddr:%s is not illegal", liteClientConfig.getLiteEventMeshAddr())); + } + eventMeshAddrList.add(eventMeshAddr); + } + eventMeshServerSelector = new RandomLoadBalanceSelector<>(eventMeshAddrList); + break; + case WEIGHT_ROUND_ROBIN: + List> eventMeshAddrWeightList = new ArrayList<>(); + for (String eventMeshAddrWight : eventMeshAddrs) { + if (!IP_PORT_WEIGHT_PATTERN.matcher(eventMeshAddrWight).matches()) { + throw new EventMeshException( + String.format("liteEventMeshAddr:%s is not illegal", liteClientConfig.getLiteEventMeshAddr())); + } + int splitIndex = eventMeshAddrWight.lastIndexOf(":"); + Weight weight = new Weight<>( + eventMeshAddrWight.substring(0, splitIndex), + Integer.parseInt(eventMeshAddrWight.substring(splitIndex + 1)) + ); + eventMeshAddrWeightList.add(weight); + } + eventMeshServerSelector = new WeightRoundRobinLoadBalanceSelector<>(eventMeshAddrWeightList); + break; + default: + // ignore + } + if (eventMeshServerSelector == null) { + throw new EventMeshException("liteEventMeshAddr param illegal,please check"); + } + return eventMeshServerSelector; + } + +} diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshClient.java index 4e11260528..afdb90ac5f 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshClient.java @@ -19,7 +19,9 @@ import org.apache.eventmesh.client.tcp.common.AsyncRRCallback; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.SubscriptionMode; public interface EventMeshClient { @@ -39,7 +41,7 @@ public interface EventMeshClient { void listen() throws Exception; - void subscribe(String topic) throws Exception; + void subscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) throws Exception; void unsubscribe() throws Exception; diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/SimpleSubClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/SimpleSubClient.java index 251fd93b27..3803edcb07 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/SimpleSubClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/SimpleSubClient.java @@ -19,6 +19,8 @@ import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; +import org.apache.eventmesh.common.protocol.SubcriptionType; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.UserAgent; public interface SimpleSubClient { @@ -30,7 +32,7 @@ public interface SimpleSubClient { void reconnect() throws Exception; - void subscribe(String topic) throws Exception; + void subscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) throws Exception; void unsubscribe() throws Exception; diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java index 4122a234a0..2d6c7ca834 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java @@ -21,10 +21,11 @@ import java.util.List; import java.util.concurrent.ThreadLocalRandom; -import org.apache.eventmesh.common.protocol.tcp.Command; -import org.apache.eventmesh.common.protocol.tcp.Header; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.Subscription; -import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.SubscriptionMode; +import org.apache.eventmesh.common.protocol.tcp.*; import org.apache.eventmesh.common.protocol.tcp.Package; public class MessageUtils { @@ -55,10 +56,10 @@ public static Package listen() { return msg; } - public static Package subscribe(String topic) { + public static Package subscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) { Package msg = new Package(); msg.setHeader(new Header(Command.SUBSCRIBE_REQUEST, 0, null, generateRandomString(seqLength))); - msg.setBody(generateSubscription(topic)); + msg.setBody(generateSubscription(topic, subscriptionMode, subcriptionType)); return msg; } @@ -98,7 +99,7 @@ public static Package responseToClientAck(Package in) { public static UserAgent generateSubClient(UserAgent agent) { UserAgent user = new UserAgent(); - user.setDcn(agent.getDcn()); + user.setEnv(agent.getEnv()); user.setHost(agent.getHost()); user.setPassword(agent.getPassword()); user.setUsername(agent.getUsername()); @@ -108,14 +109,15 @@ public static UserAgent generateSubClient(UserAgent agent) { user.setPid(agent.getPid()); user.setVersion(agent.getVersion()); user.setIdc(agent.getIdc()); - + user.setConsumerGroup(agent.getConsumerGroup()); + user.setProducerGroup(agent.getProducerGroup()); user.setPurpose(EventMeshCommon.USER_AGENT_PURPOSE_SUB); return user; } public static UserAgent generatePubClient(UserAgent agent) { UserAgent user = new UserAgent(); - user.setDcn(agent.getDcn()); + user.setEnv(agent.getEnv()); user.setHost(agent.getHost()); user.setPassword(agent.getPassword()); user.setUsername(agent.getUsername()); @@ -125,16 +127,16 @@ public static UserAgent generatePubClient(UserAgent agent) { user.setPid(agent.getPid()); user.setVersion(agent.getVersion()); user.setIdc(agent.getIdc()); - + user.setProducerGroup(agent.getProducerGroup()); user.setPurpose(EventMeshCommon.USER_AGENT_PURPOSE_PUB); return user; } - private static Subscription generateSubscription(String topic) { + private static Subscription generateSubscription(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) { Subscription subscription = new Subscription(); - List topicList = new ArrayList<>(); - topicList.add(topic); - subscription.setTopicList(topicList); + List subscriptionItems = new ArrayList<>(); + subscriptionItems.add(new SubscriptionItem(topic, subscriptionMode, subcriptionType)); + subscription.setTopicList(subscriptionItems); return subscription; } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/DefaultEventMeshClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/DefaultEventMeshClient.java index 4cc14eb46a..8e645fa35f 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/DefaultEventMeshClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/DefaultEventMeshClient.java @@ -24,7 +24,9 @@ import org.apache.eventmesh.client.tcp.common.AsyncRRCallback; import org.apache.eventmesh.client.tcp.common.MessageUtils; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.UserAgent; public class DefaultEventMeshClient implements EventMeshClient { @@ -95,8 +97,8 @@ public void listen() throws Exception { } @Override - public void subscribe(String topic) throws Exception { - this.subClient.subscribe(topic); + public void subscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) throws Exception { + this.subClient.subscribe(topic, subscriptionMode, subcriptionType); } @Override diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/SimpleSubClientImpl.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/SimpleSubClientImpl.java index 0579184156..38d52f653d 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/SimpleSubClientImpl.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/SimpleSubClientImpl.java @@ -33,10 +33,12 @@ import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.common.RequestContext; import org.apache.eventmesh.client.tcp.common.TcpClient; -import org.apache.eventmesh.common.protocol.tcp.Command; -import org.apache.eventmesh.common.protocol.tcp.UserAgent; -import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.SubcriptionType; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.SubscriptionMode; +import org.apache.eventmesh.common.protocol.tcp.*; +import org.apache.eventmesh.common.protocol.tcp.Package; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,7 +50,7 @@ public class SimpleSubClientImpl extends TcpClient implements SimpleSubClient { private ReceiveMsgHook callback; - private List topics = new ArrayList(); + private List subscriptionItems = new ArrayList(); private ScheduledFuture task; @@ -70,9 +72,9 @@ public void init() throws Exception { public void reconnect() throws Exception { super.reconnect(); hello(); - if (!CollectionUtils.isEmpty(topics)) { - for (String topic : topics) { - Package request = MessageUtils.subscribe(topic); + if (!CollectionUtils.isEmpty(subscriptionItems)) { + for (SubscriptionItem item : subscriptionItems) { + Package request = MessageUtils.subscribe(item.getTopic(), item.getMode(), item.getType()); this.io(request, EventMeshCommon.DEFAULT_TIME_OUT_MILLS); } } @@ -121,9 +123,9 @@ public void listen() throws Exception { } - public void subscribe(String topic) throws Exception { - topics.add(topic); - Package request = MessageUtils.subscribe(topic); + public void subscribe(String topic, SubscriptionMode subscriptionMode, SubcriptionType subcriptionType) throws Exception { + subscriptionItems.add(new SubscriptionItem(topic, subscriptionMode, subcriptionType)); + Package request = MessageUtils.subscribe(topic, subscriptionMode, subcriptionType); this.io(request, EventMeshCommon.DEFAULT_TIME_OUT_MILLS); } diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncPublishInstance.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncPublishInstance.java index 9eaf745742..e1598d8958 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncPublishInstance.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncPublishInstance.java @@ -39,7 +39,7 @@ public static void main(String[] args) throws Exception { // String eventMeshIPPort = args[0]; String eventMeshIPPort = ""; // final String topic = args[1]; - final String topic = "FT0-e-80010000-01-1"; + final String topic = "TEST-TOPIC-HTTP-ASYNC"; if (StringUtils.isBlank(eventMeshIPPort)) { // if has multi value, can config as: 127.0.0.1:10105;127.0.0.2:10105 eventMeshIPPort = "127.0.0.1:10105"; @@ -47,9 +47,9 @@ public static void main(String[] args) throws Exception { LiteClientConfig eventMeshClientConfig = new LiteClientConfig(); eventMeshClientConfig.setLiteEventMeshAddr(eventMeshIPPort) + .setProducerGroup("EventMeshTest-producerGroup") .setEnv("env") .setIdc("idc") - .setDcn("dcn") .setIp(IPUtil.getLocalAddress()) .setSys("1234") .setPid(String.valueOf(ThreadUtil.getPID())); diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncSyncRequestInstance.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncSyncRequestInstance.java index a03618595e..596bf95645 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncSyncRequestInstance.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncSyncRequestInstance.java @@ -40,7 +40,7 @@ public static void main(String[] args) throws Exception { // String eventMeshIPPort = args[0]; String eventMeshIPPort = ""; // final String topic = args[1]; - final String topic = "FT0-e-80010000-01-1"; + final String topic = "TEST-TOPIC-HTTP-ASYNC"; if (StringUtils.isBlank(eventMeshIPPort)) { // if has multi value, can config as: 127.0.0.1:10105;127.0.0.2:10105 eventMeshIPPort = "127.0.0.1:10105"; @@ -48,9 +48,9 @@ public static void main(String[] args) throws Exception { LiteClientConfig eventMeshClientConfig = new LiteClientConfig(); eventMeshClientConfig.setLiteEventMeshAddr(eventMeshIPPort) + .setProducerGroup("EventMeshTest-producerGroup") .setEnv("env") .setIdc("idc") - .setDcn("dcn") .setIp(IPUtil.getLocalAddress()) .setSys("1234") .setPid(String.valueOf(ThreadUtil.getPID())); diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/SyncRequestInstance.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/SyncRequestInstance.java index 22e3f40a61..b62d2948aa 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/SyncRequestInstance.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/SyncRequestInstance.java @@ -46,9 +46,9 @@ public static void main(String[] args) throws Exception { LiteClientConfig eventMeshClientConfig = new LiteClientConfig(); eventMeshClientConfig.setLiteEventMeshAddr(eventMeshIPPort) + .setProducerGroup("EventMeshTest-producerGroup") .setEnv("env") .setIdc("idc") - .setDcn("dcn") .setIp(IPUtil.getLocalAddress()) .setSys("1234") .setPid(String.valueOf(ThreadUtil.getPID())); diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtilsTest.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtilsTest.java new file mode 100644 index 0000000000..d393c24a4c --- /dev/null +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtilsTest.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.eventmesh.client.http.util; + +import org.apache.eventmesh.client.http.conf.LiteClientConfig; +import org.apache.eventmesh.common.EventMeshException; +import org.apache.eventmesh.common.loadbalance.LoadBalanceSelector; +import org.apache.eventmesh.common.loadbalance.LoadBalanceType; +import org.junit.Assert; +import org.junit.Test; + +public class HttpLoadBalanceUtilsTest { + + @Test + public void testCreateRandomSelector() throws EventMeshException { + LiteClientConfig liteClientConfig = new LiteClientConfig() + .setLiteEventMeshAddr("127.0.0.1:1001;127.0.0.2:1002"); + LoadBalanceSelector randomSelector = HttpLoadBalanceUtils + .createEventMeshServerLoadBalanceSelector(liteClientConfig); + Assert.assertEquals(LoadBalanceType.RANDOM, randomSelector.getType()); + } + + @Test + public void testCreateWeightRoundRobinSelector() throws EventMeshException { + LiteClientConfig liteClientConfig = new LiteClientConfig() + .setLiteEventMeshAddr("127.0.0.1:1001:1;127.0.0.2:1001:2") + .setLoadBalanceType(LoadBalanceType.WEIGHT_ROUND_ROBIN); + LoadBalanceSelector weightRoundRobinSelector = HttpLoadBalanceUtils + .createEventMeshServerLoadBalanceSelector(liteClientConfig); + Assert.assertEquals(LoadBalanceType.WEIGHT_ROUND_ROBIN, weightRoundRobinSelector.getType()); + } +} \ No newline at end of file diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestCaseTopicSet.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestCaseTopicSet.java index 171b3d9e10..669e598a8c 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestCaseTopicSet.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestCaseTopicSet.java @@ -23,12 +23,12 @@ public class EventMeshTestCaseTopicSet { // public static final String TOPIC_PRX_WQ2ClientBroadCast = "topic-broadcast-test"; - public static final String TOPIC_PRX_WQ2ClientBroadCast = "FT0-e-80030001-01-3"; + public static final String TOPIC_PRX_WQ2ClientBroadCast = "TEST-TOPIC-TCP-BROADCAST"; // public static final String TOPIC_PRX_SyncSubscribeTest = "topic-sync-test"; - public static final String TOPIC_PRX_SyncSubscribeTest = "FT0-s-80000000-01-0"; + public static final String TOPIC_PRX_SyncSubscribeTest = "TEST-TOPIC-TCP-SYNC"; // public static final String TOPIC_PRX_WQ2ClientUniCast = "topic-async-test"; - public static final String TOPIC_PRX_WQ2ClientUniCast = "FT0-e-80010000-01-1"; + public static final String TOPIC_PRX_WQ2ClientUniCast = "TEST-TOPIC-TCP-ASYNC"; } diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestUtils.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestUtils.java index a34f523788..78e1016756 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestUtils.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestUtils.java @@ -39,10 +39,11 @@ public class EventMeshTestUtils { public static UserAgent generateClient1() { UserAgent user = new UserAgent(); - user.setDcn("AC0"); user.setHost("127.0.0.1"); user.setPassword(generateRandomString(8)); user.setUsername("PU4283"); + user.setConsumerGroup("EventmeshTest-ConsumerGroup"); + user.setProducerGroup("EventmeshTest-ProducerGroup"); user.setPath("/data/app/umg_proxy"); user.setPort(8362); user.setSubsystem("5023"); @@ -54,10 +55,11 @@ public static UserAgent generateClient1() { public static UserAgent generateClient2() { UserAgent user = new UserAgent(); - user.setDcn("FT0"); user.setHost("127.0.0.1"); user.setPassword(generateRandomString(8)); user.setUsername("PU4283"); + user.setConsumerGroup("EventmeshTest-ConsumerGroup"); + user.setProducerGroup("EventmeshTest-ProducerGroup"); user.setPath("/data/app/umg_proxy"); user.setPort(9362); user.setSubsystem("5017"); diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/demo/AsyncSubscribe.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/demo/AsyncSubscribe.java index 319e428772..9f0fb0c4b1 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/demo/AsyncSubscribe.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/demo/AsyncSubscribe.java @@ -24,6 +24,8 @@ import org.apache.eventmesh.client.tcp.common.EventMeshTestUtils; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.impl.DefaultEventMeshClient; +import org.apache.eventmesh.common.protocol.SubcriptionType; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.common.protocol.tcp.Package; @@ -45,7 +47,7 @@ public static void main(String[] agrs) throws Exception { client.init(); client.heartbeat(); - client.subscribe("FT0-e-80010000-01-1"); + client.subscribe("TEST-TOPIC-TCP-ASYNC", SubscriptionMode.CLUSTERING, SubcriptionType.ASYNC); client.registerSubBusiHandler(handler); client.listen(); diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/demo/AsyncSubscribeBroadcast.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/demo/AsyncSubscribeBroadcast.java index 8b77e1a3a9..4a5e121f10 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/demo/AsyncSubscribeBroadcast.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/demo/AsyncSubscribeBroadcast.java @@ -24,6 +24,8 @@ import org.apache.eventmesh.client.tcp.common.EventMeshTestUtils; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.impl.DefaultEventMeshClient; +import org.apache.eventmesh.common.protocol.SubcriptionType; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.common.protocol.tcp.Package; @@ -45,7 +47,7 @@ public static void main(String[] agrs) throws Exception { client.init(); client.heartbeat(); - client.subscribe("FT0-e-80030001-01-3"); + client.subscribe("TEST-TOPIC-TCP-BROADCAST", SubscriptionMode.BROADCASTING, SubcriptionType.ASYNC); client.registerSubBusiHandler(handler); client.listen(); diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/demo/SyncResponse.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/demo/SyncResponse.java index b4fbbf71af..d4b93a9fcf 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/demo/SyncResponse.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/demo/SyncResponse.java @@ -23,6 +23,8 @@ import org.apache.eventmesh.client.tcp.common.EventMeshTestUtils; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.impl.DefaultEventMeshClient; +import org.apache.eventmesh.common.protocol.SubcriptionType; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.common.protocol.tcp.Package; import org.slf4j.Logger; @@ -43,7 +45,7 @@ public static void main(String[] agrs) throws Exception { client.init(); client.heartbeat(); - client.subscribe("FT0-s-80000000-01-0"); + client.subscribe("TEST-TOPIC-TCP-SYNC", SubscriptionMode.CLUSTERING, SubcriptionType.SYNC); //同步RR消息 client.registerSubBusiHandler(handler); diff --git a/eventmesh-starter/gradle.properties b/eventmesh-starter/gradle.properties index ca5d73fd13..6446ff31f4 100644 --- a/eventmesh-starter/gradle.properties +++ b/eventmesh-starter/gradle.properties @@ -15,6 +15,6 @@ # limitations under the License. # group=org.apache.eventmesh -version=1.2.0 +version=1.2.0-release mavenUserName= mavenPassword= diff --git a/eventmesh-test/gradle.properties b/eventmesh-test/gradle.properties index ca5d73fd13..6446ff31f4 100644 --- a/eventmesh-test/gradle.properties +++ b/eventmesh-test/gradle.properties @@ -15,6 +15,6 @@ # limitations under the License. # group=org.apache.eventmesh -version=1.2.0 +version=1.2.0-release mavenUserName= mavenPassword= diff --git a/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/AsyncPublishInstance.java b/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/AsyncPublishInstance.java index b718bcc2e0..c58c7bf9c0 100644 --- a/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/AsyncPublishInstance.java +++ b/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/AsyncPublishInstance.java @@ -35,6 +35,9 @@ public class AsyncPublishInstance { public static Logger logger = LoggerFactory.getLogger(AsyncPublishInstance.class); + // This messageSize is also used in SubService.java (Subscriber) + public static int messageSize = 5; + public static void main(String[] args) throws Exception { Properties properties = Utils.readPropertiesFile("application.properties"); final String eventMeshIp = properties.getProperty("eventmesh.ip"); @@ -45,7 +48,7 @@ public static void main(String[] args) throws Exception { // String eventMeshIPPort = args[0]; String eventMeshIPPort = eventMeshIp + ":" + eventMeshHttpPort; // final String topic = args[1]; - final String topic = "FT0-e-80010001-01-1"; + final String topic = "TEST-TOPIC-HTTP-ASYNC"; if (StringUtils.isBlank(eventMeshIPPort)) { // if has multi value, can config as: 127.0.0.1:10105;127.0.0.2:10105 eventMeshIPPort = "127.0.0.1:10105"; @@ -53,16 +56,16 @@ public static void main(String[] args) throws Exception { LiteClientConfig eventMeshClientConfig = new LiteClientConfig(); eventMeshClientConfig.setLiteEventMeshAddr(eventMeshIPPort) + .setProducerGroup("EventMeshTest-producerGroup") .setEnv("env") .setIdc("idc") - .setDcn("dcn") .setIp(IPUtil.getLocalAddress()) .setSys("1234") .setPid(String.valueOf(ThreadUtil.getPID())); liteProducer = new LiteProducer(eventMeshClientConfig); liteProducer.start(); - for (int i = 0; i < 5; i++) { + for (int i = 0; i < messageSize; i++) { LiteMessage liteMessage = new LiteMessage(); liteMessage.setBizSeqNo(RandomStringUtils.randomNumeric(30)) // .setContent("contentStr with special protocal") diff --git a/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/AsyncSyncRequestInstance.java b/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/AsyncSyncRequestInstance.java index 54b2f2cbca..cc8a536011 100644 --- a/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/AsyncSyncRequestInstance.java +++ b/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/AsyncSyncRequestInstance.java @@ -46,7 +46,7 @@ public static void main(String[] args) throws Exception { // String eventMeshIPPort = args[0]; String eventMeshIPPort = eventMeshIp + ":" + eventMeshHttpPort; // final String topic = args[1]; - final String topic = "FT0-e-80010000-01-1"; + final String topic = "TEST-TOPIC-TCP-ASYNC"; if (StringUtils.isBlank(eventMeshIPPort)) { // if has multi value, can config as: 127.0.0.1:10105;127.0.0.2:10105 eventMeshIPPort = "127.0.0.1:10105"; @@ -54,9 +54,9 @@ public static void main(String[] args) throws Exception { LiteClientConfig eventMeshClientConfig = new LiteClientConfig(); eventMeshClientConfig.setLiteEventMeshAddr(eventMeshIPPort) + .setProducerGroup("EventMeshTest-producerGroup") .setEnv("env") .setIdc("idc") - .setDcn("dcn") .setIp(IPUtil.getLocalAddress()) .setSys("1234") .setPid(String.valueOf(ThreadUtil.getPID())); diff --git a/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/SyncRequestInstance.java b/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/SyncRequestInstance.java index 239beeadde..9d3af8ffe4 100644 --- a/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/SyncRequestInstance.java +++ b/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/SyncRequestInstance.java @@ -46,9 +46,9 @@ public static void main(String[] args) throws Exception { LiteClientConfig eventMeshClientConfig = new LiteClientConfig(); eventMeshClientConfig.setLiteEventMeshAddr(eventMeshIPPort) + .setProducerGroup("EventMeshTest-producerGroup") .setEnv("env") .setIdc("idc") - .setDcn("dcn") .setIp(IPUtil.getLocalAddress()) .setSys("1234") .setPid(String.valueOf(ThreadUtil.getPID())); diff --git a/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/sub/controller/SubController.java b/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/sub/controller/SubController.java index 8f8a7a7f9b..92ca09d700 100644 --- a/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/sub/controller/SubController.java +++ b/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/sub/controller/SubController.java @@ -19,8 +19,10 @@ import com.alibaba.fastjson.JSONObject; +import org.apache.eventmesh.http.demo.sub.service.SubService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -33,9 +35,14 @@ public class SubController { public static Logger logger = LoggerFactory.getLogger(SubController.class); + @Autowired + private SubService subService; + @RequestMapping(value = "/test", method = RequestMethod.POST) public String subTest(@RequestBody String message) { logger.info("=======receive message======= {}", JSONObject.toJSONString(message)); + subService.consumeMessage(message); + JSONObject result = new JSONObject(); result.put("retCode", 1); return result.toJSONString(); diff --git a/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/sub/service/SubService.java b/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/sub/service/SubService.java index e20fea98be..570b24d7e6 100644 --- a/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/sub/service/SubService.java +++ b/eventmesh-test/src/main/java/org/apache/eventmesh/http/demo/sub/service/SubService.java @@ -1,20 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + package org.apache.eventmesh.http.demo.sub.service; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Properties; - +import java.util.concurrent.CountDownLatch; import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.client.http.conf.LiteClientConfig; import org.apache.eventmesh.client.http.consumer.LiteConsumer; import org.apache.eventmesh.common.EventMeshException; import org.apache.eventmesh.common.IPUtil; import org.apache.eventmesh.common.ThreadUtil; +import org.apache.eventmesh.common.protocol.SubcriptionType; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.SubscriptionMode; +import org.apache.eventmesh.http.demo.AsyncPublishInstance; import org.apache.eventmesh.util.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.stereotype.Component; +import javax.annotation.PreDestroy; @Component public class SubService implements InitializingBean { @@ -27,7 +52,7 @@ public class SubService implements InitializingBean { final Properties properties = Utils.readPropertiesFile("application.properties"); - final List topicList = Arrays.asList("FT0-e-80010001-01-1"); + final List topicList = Arrays.asList(new SubscriptionItem("TEST-TOPIC-HTTP-ASYNC", SubscriptionMode.CLUSTERING, SubcriptionType.ASYNC)); final String localIp = IPUtil.getLocalAddress(); final String localPort = properties.getProperty("server.port"); final String eventMeshIp = properties.getProperty("eventmesh.ip"); @@ -35,9 +60,11 @@ public class SubService implements InitializingBean { final String url = "http://" + localIp + ":" + localPort + "/sub/test"; final String env = "P"; final String idc = "FT"; - final String dcn = "FT0"; final String subsys = "1234"; + // CountDownLatch size is the same as messageSize in AsyncPublishInstance.java (Publisher) + private CountDownLatch countDownLatch = new CountDownLatch(AsyncPublishInstance.messageSize); + @Override public void afterPropertiesSet() throws Exception { @@ -47,9 +74,9 @@ public void afterPropertiesSet() throws Exception { } LiteClientConfig eventMeshClientConfig = new LiteClientConfig(); eventMeshClientConfig.setLiteEventMeshAddr(eventMeshIPPort) + .setConsumerGroup("EventMeshTest-consumerGroup") .setEnv(env) .setIdc(idc) - .setDcn(dcn) .setIp(IPUtil.getLocalAddress()) .setSys(subsys) .setPid(String.valueOf(ThreadUtil.getPID())); @@ -59,28 +86,45 @@ public void afterPropertiesSet() throws Exception { liteConsumer.heartBeat(topicList, url); liteConsumer.subscribe(topicList, url); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - logger.info("start destory ...."); - try { - liteConsumer.unsubscribe(topicList, url); - } catch (EventMeshException e) { - e.printStackTrace(); - } + // Wait for all messaged to be consumed + Thread stopThread = new Thread(() -> { try { - liteConsumer.shutdown(); - } catch (Exception e) { + countDownLatch.await(); + } catch (InterruptedException e) { e.printStackTrace(); } - logger.info("end destory."); - })); - - Thread stopThread = new Thread(() -> { logger.info("stopThread start...."); System.exit(0); }); + stopThread.start(); + } - Thread.sleep(5 * 60 * 1000); + @PreDestroy + public void cleanup() { + logger.info("start destory ...."); + try { + List unSubList = new ArrayList<>(); + for (SubscriptionItem item:topicList) { + unSubList.add(item.getTopic()); + } + liteConsumer.unsubscribe(unSubList, url); + } catch (Exception e) { + e.printStackTrace(); + } + try { + liteConsumer.shutdown(); + } catch (Exception e) { + e.printStackTrace(); + } + logger.info("end destory."); + } -// stopThread.start(); + /** + * Count the message already consumed + */ + public void consumeMessage(String msg) { + logger.info("consume message {}", msg); + countDownLatch.countDown(); + logger.info("remaining number of messages to be consumed {}", countDownLatch.getCount()); } } diff --git a/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestCaseTopicSet.java b/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestCaseTopicSet.java index e229c85184..dd7908cb55 100644 --- a/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestCaseTopicSet.java +++ b/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestCaseTopicSet.java @@ -23,12 +23,12 @@ public class EventMeshTestCaseTopicSet { // public static final String TOPIC_PRX_WQ2ClientBroadCast = "topic-broadcast-test"; - public static final String TOPIC_PRX_WQ2ClientBroadCast = "FT0-e-80030000-01-3"; + public static final String TOPIC_PRX_WQ2ClientBroadCast = "TEST-TOPIC-TCP-BROADCAST"; // public static final String TOPIC_PRX_SyncSubscribeTest = "topic-sync-test"; - public static final String TOPIC_PRX_SyncSubscribeTest = "FT0-s-80000000-01-0"; + public static final String TOPIC_PRX_SyncSubscribeTest = "TEST-TOPIC-TCP-SYNC"; // public static final String TOPIC_PRX_WQ2ClientUniCast = "topic-async-test"; - public static final String TOPIC_PRX_WQ2ClientUniCast = "FT0-e-80010000-01-1"; + public static final String TOPIC_PRX_WQ2ClientUniCast = "TEST-TOPIC-TCP-ASYNC"; } diff --git a/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestUtils.java b/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestUtils.java index dedce3a05b..88f5016e9d 100644 --- a/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestUtils.java +++ b/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestUtils.java @@ -24,6 +24,7 @@ import java.util.concurrent.ThreadLocalRandom; +import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Header; @@ -35,10 +36,12 @@ public class EventMeshTestUtils { public static UserAgent generateClient1() { UserAgent user = new UserAgent(); - user.setDcn("AC0"); + user.setEnv("test"); user.setHost("127.0.0.1"); user.setPassword(generateRandomString(8)); user.setUsername("PU4283"); + user.setProducerGroup("EventmeshTest-ProducerGroup"); + user.setConsumerGroup("EventmeshTest-ConsumerGroup"); user.setPath("/data/app/umg_proxy"); user.setPort(8362); user.setSubsystem("5023"); @@ -50,10 +53,12 @@ public static UserAgent generateClient1() { public static UserAgent generateClient2() { UserAgent user = new UserAgent(); - user.setDcn("FT0"); + user.setEnv("test"); user.setHost("127.0.0.1"); user.setPassword(generateRandomString(8)); user.setUsername("PU4283"); + user.setConsumerGroup("EventmeshTest-ConsumerGroup"); + user.setProducerGroup("EventmeshTest-ProducerGroup"); user.setPath("/data/app/umg_proxy"); user.setPort(9362); user.setSubsystem("5017"); diff --git a/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/demo/AsyncSubscribe.java b/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/demo/AsyncSubscribe.java index 1f7d3c89b3..e1db99e909 100644 --- a/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/demo/AsyncSubscribe.java +++ b/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/demo/AsyncSubscribe.java @@ -24,8 +24,10 @@ import org.apache.eventmesh.client.tcp.EventMeshClient; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.impl.DefaultEventMeshClient; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.tcp.common.EventMeshTestUtils; import org.apache.eventmesh.util.Utils; @@ -50,7 +52,7 @@ public static void main(String[] agrs) throws Exception { client.init(); client.heartbeat(); - client.subscribe("FT0-e-80010000-01-1"); + client.subscribe("TEST-TOPIC-TCP-ASYNC", SubscriptionMode.CLUSTERING, SubcriptionType.ASYNC); client.registerSubBusiHandler(handler); client.listen(); diff --git a/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/demo/AsyncSubscribeBroadcast.java b/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/demo/AsyncSubscribeBroadcast.java index 74bdaaa212..38936f99c8 100644 --- a/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/demo/AsyncSubscribeBroadcast.java +++ b/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/demo/AsyncSubscribeBroadcast.java @@ -24,8 +24,10 @@ import org.apache.eventmesh.client.tcp.EventMeshClient; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.impl.DefaultEventMeshClient; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.tcp.common.EventMeshTestUtils; import org.apache.eventmesh.util.Utils; @@ -50,7 +52,7 @@ public static void main(String[] agrs) throws Exception { client.init(); client.heartbeat(); - client.subscribe("FT0-e-80030000-01-3"); + client.subscribe("TEST-TOPIC-TCP-BROADCAST", SubscriptionMode.BROADCASTING, SubcriptionType.ASYNC); client.registerSubBusiHandler(handler); client.listen(); diff --git a/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/demo/SyncResponse.java b/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/demo/SyncResponse.java index 969163d44b..d87d4f465e 100644 --- a/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/demo/SyncResponse.java +++ b/eventmesh-test/src/main/java/org/apache/eventmesh/tcp/demo/SyncResponse.java @@ -22,7 +22,9 @@ import org.apache.eventmesh.client.tcp.EventMeshClient; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.impl.DefaultEventMeshClient; +import org.apache.eventmesh.common.protocol.SubcriptionType; import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.tcp.common.EventMeshTestUtils; import org.slf4j.Logger; @@ -34,6 +36,7 @@ public class SyncResponse implements ReceiveMsgHook { private static EventMeshClient client; + public static SyncResponse handler = new SyncResponse(); public static void main(String[] agrs) throws Exception { @@ -43,7 +46,7 @@ public static void main(String[] agrs) throws Exception { client.init(); client.heartbeat(); - client.subscribe("FT0-s-80000000-01-0"); + client.subscribe("TEST-TOPIC-TCP-SYNC", SubscriptionMode.CLUSTERING, SubcriptionType.SYNC); //同步RR消息 client.registerSubBusiHandler(handler); diff --git a/gradle.properties b/gradle.properties index 6682094d53..38938bbb06 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,4 +28,4 @@ signing.secretKeyRingFile= apacheUserName= #apache password apachePassWord= -signEnabled=true +signEnabled=false diff --git a/gradlew b/gradlew index fbd7c51583..7b957476e1 100755 --- a/gradlew +++ b/gradlew @@ -1,19 +1,21 @@ #!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. # -# 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 +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 # -# https://www.apache.org/licenses/LICENSE-2.0 +# 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. +# 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. # ############################################################################## diff --git a/gradlew.bat b/gradlew.bat index 5093609d51..192f884777 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,17 +1,20 @@ @rem -@rem Copyright 2015 the original author or authors. +@rem Licensed to the Apache Software Foundation (ASF) under one +@rem or more contributor license agreements. See the NOTICE file +@rem distributed with this work for additional information +@rem regarding copyright ownership. The ASF licenses this file +@rem to you under the Apache License, Version 2.0 (the +@rem "License"); you may not use this file except in compliance +@rem with the License. You may obtain a copy of the License at @rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at +@rem http://www.apache.org/licenses/LICENSE-2.0 @rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. +@rem Unless required by applicable law or agreed to in writing, +@rem software distributed under the License is distributed on an +@rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@rem KIND, either express or implied. See the License for the +@rem specific language governing permissions and limitations +@rem under the License. @rem @if "%DEBUG%" == "" @echo off diff --git a/install.sh b/install.sh index 04e66998ef..19397ac752 100644 --- a/install.sh +++ b/install.sh @@ -1,5 +1,23 @@ #!/usr/bin/env bash # +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + # -Pdev=true : snapshot version # -Pjdk=1.8 : jdk version,default 1.8 # dist : resource collect