Skip to content

Commit

Permalink
[ISSUE #4]Namesrv support broker registration and get cluster info re…
Browse files Browse the repository at this point in the history
…quest code
  • Loading branch information
mxsm committed Dec 30, 2023
1 parent e60e366 commit d32c72d
Show file tree
Hide file tree
Showing 61 changed files with 6,286 additions and 3 deletions.
119 changes: 119 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: 'CI'
on:
pull_request:
push:
branches:
- main

env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always

jobs:
ci-pass:
name: CI is green
runs-on: ubuntu-latest
needs:
- test-linux
- test-linux-aarch64
- test-macos
- test-windows
- lint
steps:
- run: exit 0

test-linux:
runs-on: [ self-hosted, X64 ]

steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
# - uses: Swatinem/rust-cache@v1
- name: Run tests
run: |
cargo check --features multiplex
cargo test
test-linux-aarch64:
runs-on: [ self-hosted, arm ]

steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
# - uses: Swatinem/rust-cache@v1
- name: Run tests
run: |
cargo check --features multiplex
cargo test
test-macos:
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- uses: Swatinem/rust-cache@v1
- name: Run tests
run: |
cargo check --features multiplex
cargo test
test-windows:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- uses: Swatinem/rust-cache@v1
- name: Run tests
run: |
cargo check --features multiplex
cargo test
lint:
runs-on: [ self-hosted, X64 ]

steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy
# - uses: Swatinem/rust-cache@v1
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Format check
run: |
cargo fmt -- --check
build:
runs-on: ubuntu-latest

strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
rust: [ nightly ]

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: ${{ matrix.rust }}
override: true

- name: Build
run: cargo build --verbose

- name: Test
run: cargo test --verbose
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

.vscode
.idea
46 changes: 46 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[workspace]
members = [
"common",
"namesrv",
"remoting"
]
resolver = "2"

[workspace.package]
authors = ["mxsm <[email protected]>"]
edition = "2021"
homepage = "https://github.com/mxsm/rocketmq-rust"
repository = "https://github.com/mxsm/rocketmq-rust"
license = "MIT OR Apache-2.0"
keywords = ["rocketmq", "rust", "mq"]
readme = "README.md"
description = """
Unofficial Rust implementation of Apache RocketMQ
"""
[workspace.dependencies]
tokio = { version = "1.35", features = ["full"] }
tokio-util = {version = "0.7.10",features = ["full"]}
tokio-stream = {version = "0.1.14",features = ["full"]}

log = "0.4.0"
env_logger = "0.10.0"
tracing = "0.1"
tracing-subscriber = "0.3"

thiserror = "1.0.51"


#serde
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

anyhow = "1.0"

bytes = "1.5.0"

rand = "0.8.5"

lazy_static = "1.4.0"

[workspace.dev-dependencies]
env_logger = "0.10.0"
File renamed without changes.
25 changes: 25 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2022 Volo Contributors

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
5 changes: 3 additions & 2 deletions README-zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ Rocketmq非官方的Rust实现

### Broker管理

- [ ] [WIP]Broker注册
- [ ] HeartBeat消息处理
- [ ] **Broker注册(请求码:103)**
- [ ] **获取集群信息(请求码:106)**
- [ ] **HeartBeat消息处理**

TODO

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ The specific functions of each module can be referred to in the [official Rocket

### Broker Management

- [ ] **[WIP] Broker registration**
- [ ] **Broker registration(request code: 103)**
- [ ] **Retrieve cluster information(request code: 106)**
- [ ] **Heartbeat message processing**

TODO
Expand Down
21 changes: 21 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "rocketmq-common"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
crc32fast = "1.3.2"

#json spupport
serde.workspace = true
serde_json.workspace = true
77 changes: 77 additions & 0 deletions common/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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.
*/

use std::fmt;

use serde::{Deserialize, Deserializer, Serialize, Serializer};

pub mod config;
pub mod constant;
pub mod mix_all;
pub mod mq_version;

#[derive(Debug, Clone)]
pub enum TopicFilterType {
SingleTag,
MultiTag,
}

impl Serialize for TopicFilterType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let value = match self {
TopicFilterType::SingleTag => "SINGLE_TAG",
TopicFilterType::MultiTag => "MULTI_TAG",
};
serializer.serialize_str(value)
}
}

impl<'de> Deserialize<'de> for TopicFilterType {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct TopicFilterTypeVisitor;

impl<'de> serde::de::Visitor<'de> for TopicFilterTypeVisitor {
type Value = TopicFilterType;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a string representing TopicFilterType")
}

fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
match value {
"SINGLE_TAG" => Ok(TopicFilterType::SingleTag),
"MULTI_TAG" => Ok(TopicFilterType::MultiTag),
_ => Err(serde::de::Error::unknown_variant(
value,
&["SingleTag", "MultiTag"],
)),
}
}
}

deserializer.deserialize_str(TopicFilterTypeVisitor)
}
}
64 changes: 64 additions & 0 deletions common/src/common/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

use super::TopicFilterType;

const SEPARATOR: &str = " ";
const DEFAULT_READ_QUEUE_NUMS: u32 = 16;
const DEFAULT_WRITE_QUEUE_NUMS: u32 = 16;

#[derive(Debug)]
/*
* 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.
*/
#[derive(Clone, Serialize, Deserialize)]
pub struct TopicConfig {
#[serde(rename = "topicName")]
pub topic_name: String,
#[serde(rename = "readQueueNums")]
pub read_queue_nums: u32,
#[serde(rename = "writeQueueNums")]
pub write_queue_nums: u32,
pub perm: u32,
#[serde(rename = "topicFilterType")]
pub topic_filter_type: TopicFilterType,
#[serde(rename = "topicSysFlag")]
pub topic_sys_flag: u32,
pub order: bool,
pub attributes: HashMap<String, String>,
}

impl Default for TopicConfig {
fn default() -> Self {
Self {
topic_name: "".to_string(),
read_queue_nums: DEFAULT_READ_QUEUE_NUMS,
write_queue_nums: DEFAULT_WRITE_QUEUE_NUMS,
perm: Default::default(),
topic_filter_type: TopicFilterType::MultiTag,
topic_sys_flag: Default::default(),
order: Default::default(),
attributes: Default::default(),
}
}
}

impl TopicConfig {
pub fn new() -> Self {
Self::default()
}
}
Loading

0 comments on commit d32c72d

Please sign in to comment.