Skip to content

Commit

Permalink
[ISSUE #868]Add a Producer example
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsm committed Aug 3, 2024
1 parent 85bbbd4 commit 84ffc42
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rocketmq-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ lazy_static = { workspace = true }
tracing.workspace = true
tracing-subscriber.workspace = true

[[example]]
name = "simple-producer"
path = "examples/producer/simple_producer.rs"
43 changes: 43 additions & 0 deletions rocketmq-client/examples/producer/simple_producer.rs
Original file line number Diff line number Diff line change
@@ -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.
*/
use rocketmq_client::producer::default_mq_producer::DefaultMQProducer;
use rocketmq_client::producer::mq_producer::MQProducer;
use rocketmq_client::Result;
use rocketmq_rust::rocketmq;

pub const MESSAGE_COUNT: usize = 1;
pub const PRODUCER_GROUP: &str = "please_rename_unique_group_name";
pub const DEFAULT_NAMESRVADDR: &str = "127.0.0.1:9876";
pub const TOPIC: &str = "TopicTest";
pub const TAG: &str = "TagA";

#[rocketmq::main]
pub async fn main() -> Result<()> {
// create a producer builder with default configuration
let builder = DefaultMQProducer::builder();

let mut producer = builder
.producer_group(PRODUCER_GROUP.to_string())
.name_server_addr(DEFAULT_NAMESRVADDR.to_string())
.build();

producer.start().await?;

producer.shutdown().await;

Ok(())
}

0 comments on commit 84ffc42

Please sign in to comment.