Skip to content

Commit 40ed32a

Browse files
committed
initial
1 parent ec5550e commit 40ed32a

File tree

6 files changed

+698
-1
lines changed

6 files changed

+698
-1
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ Cargo.lock
88

99
# These are backup files generated by rustfmt
1010
**/*.rs.bk
11+
12+
13+
# Added by cargo
14+
#
15+
# already existing elements were commented out
16+
17+
/target
18+
#Cargo.lock
19+
/deps

Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "tibco_ems-sys"
3+
version = "0.0.1"
4+
authors = ["Jens Walter <[email protected]>"]
5+
edition = "2018"
6+
license = "Apache-2.0"
7+
keywords = ["tibco","ems"]
8+
repository = "https://github.com/apimeister/tibco-ems-sys-rs/"
9+
description = "Rust bindings for the Tibco EMS C library."
10+
11+
[lib]
12+
name = "tibco_ems_sys"
13+
14+
[dependencies]

README.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,80 @@
1-
# tibco-ems-sys-rs
1+
# tibco_ems-sys
2+
[![Latest Version](https://img.shields.io/crates/v/tibco_ems-sys.svg)](https://crates.io/crates/tibco_ems-sys)
3+
4+
Rust bindings for the Tibco EMS C library.
5+
6+
A high-level API is provided through the `tibco_ems` crate.
7+
8+
[![Latest Version](https://img.shields.io/crates/v/tibco_ems.svg)](https://crates.io/crates/tibco_ems)
9+
10+
11+
# License
12+
tibco_ems is licensed under Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0).
13+
14+
TIBCO Enterprise Messaging Service, and all related components therein are property of TIBCO Software, and are not provided with this software package. Refer to your own TIBCO License terms for details.
15+
16+
# Build
17+
18+
To build this crate, the TIBCO EMS C library must either be in the LD_LIBRARY_PATH or alternatively a EMS_HOME environment variable must be set.
19+
20+
## Usage
21+
22+
Put this in your `Cargo.toml`:
23+
24+
```text
25+
[dependencies]
26+
tibco_ems-sys = "0.1"
27+
```
28+
29+
## Examples
30+
31+
Sending a text message to a queue.
32+
33+
```rust
34+
use tibco_ems::c_binding::*;
35+
use std::ffi::CString;
36+
37+
fn main() {
38+
unsafe{
39+
let factory = tibemsConnectionFactory_Create();
40+
41+
let url = "tcp://localhost:7222";
42+
let user="admin";
43+
let password="admin";
44+
45+
let status = tibemsConnectionFactory_SetServerURL(factory, CString::new(url).unwrap().as_ptr());
46+
println!("tibemsConnectionFactory_SetServerURL: {:?}",status);
47+
48+
let mut conn: usize = 0;
49+
let status = tibemsConnectionFactory_CreateConnection(factory,&mut conn,CString::new(user).unwrap().as_ptr(),CString::new(password).unwrap().as_ptr());
50+
println!("tibemsConnectionFactory_CreateConnection: {:?}",status);
51+
52+
let mut sess: usize = 0;
53+
let status = tibemsConnection_CreateSession(conn,&mut sess,tibems_bool::TIBEMS_FALSE,tibemsAcknowledgeMode::TIBEMS_AUTO_ACKNOWLEDGE);
54+
println!("tibemsConnection_CreateSession: {:?}",status);
55+
56+
let dest_str = "myqueue";
57+
let mut dest: usize = 0;
58+
let status = tibemsDestination_Create(&mut dest, tibemsDestinationType::TIBEMS_QUEUE, CString::new(dest_str).unwrap().as_ptr());
59+
println!("tibemsDestination_Create: {:?}",status);
60+
61+
let mut producer: usize = 0;
62+
let status = tibemsSession_CreateProducer(sess,&mut producer,dest);
63+
println!("tibemsSession_CreateProducer: {:?}",status);
64+
65+
let mut msg: usize = 0;
66+
let status = tibemsTextMsg_Create(&mut msg);
67+
println!("tibemsTextMsg_Create: {:?}",status);
68+
69+
let content="hallo welt";
70+
let status = tibemsTextMsg_SetText(msg,CString::new(content).unwrap().as_ptr());
71+
println!("tibemsTextMsg_SetText: {:?}",status);
72+
73+
let status = tibemsMsg_SetStringProperty(msg,CString::new("key").unwrap().as_ptr(),CString::new("val").unwrap().as_ptr());
74+
println!("tibemsMsg_SetStringProperty: {:?}",status);
75+
76+
let status = tibemsMsgProducer_Send(producer, msg);
77+
println!("tibemsMsgProducer_Send: {:?}",status);
78+
}
79+
}
80+
```

build.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
fn main() {
3+
match std::env::var("EMS_HOME") {
4+
Ok(directory) => {
5+
println!("cargo:rustc-link-search=native={}", directory);
6+
println!("cargo:rustc-link-search=native={}/lib", directory);
7+
println!("cargo:rustc-link-search=native={}/lib/64", directory);
8+
},
9+
Err(_err) => {}
10+
}
11+
println!("cargo:rerun-if-env-changed=EMS_HOME");
12+
println!("cargo:rustc-link-lib=dylib=tibems64");
13+
println!("cargo:rustc-link-lib=dylib=tibemsadmin64");
14+
}

examples/send_text_message.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use tibco_ems_sys::*;
2+
use std::ffi::CString;
3+
4+
fn main() {
5+
unsafe{
6+
let factory = tibemsConnectionFactory_Create();
7+
8+
let url = "tcp://localhost:7222";
9+
let user="admin";
10+
let password="admin";
11+
12+
let status = tibemsConnectionFactory_SetServerURL(factory, CString::new(url).unwrap().as_ptr());
13+
println!("tibemsConnectionFactory_SetServerURL: {:?}",status);
14+
15+
let mut conn: usize = 0;
16+
let status = tibemsConnectionFactory_CreateConnection(factory,&mut conn,CString::new(user).unwrap().as_ptr(),CString::new(password).unwrap().as_ptr());
17+
println!("tibemsConnectionFactory_CreateConnection: {:?}",status);
18+
19+
let mut sess: usize = 0;
20+
let status = tibemsConnection_CreateSession(conn,&mut sess,tibems_bool::TIBEMS_FALSE,tibemsAcknowledgeMode::TIBEMS_AUTO_ACKNOWLEDGE);
21+
println!("tibemsConnection_CreateSession: {:?}",status);
22+
23+
let dest_str = "myqueue";
24+
let mut dest: usize = 0;
25+
let status = tibemsDestination_Create(&mut dest, tibemsDestinationType::TIBEMS_QUEUE, CString::new(dest_str).unwrap().as_ptr());
26+
println!("tibemsDestination_Create: {:?}",status);
27+
28+
let mut producer: usize = 0;
29+
let status = tibemsSession_CreateProducer(sess,&mut producer,dest);
30+
println!("tibemsSession_CreateProducer: {:?}",status);
31+
32+
let mut msg: usize = 0;
33+
let status = tibemsTextMsg_Create(&mut msg);
34+
println!("tibemsTextMsg_Create: {:?}",status);
35+
36+
let content="hallo welt";
37+
let status = tibemsTextMsg_SetText(msg,CString::new(content).unwrap().as_ptr());
38+
println!("tibemsTextMsg_SetText: {:?}",status);
39+
40+
let status = tibemsMsg_SetStringProperty(msg,CString::new("key").unwrap().as_ptr(),CString::new("val").unwrap().as_ptr());
41+
println!("tibemsMsg_SetStringProperty: {:?}",status);
42+
43+
let status = tibemsMsgProducer_Send(producer, msg);
44+
println!("tibemsMsgProducer_Send: {:?}",status);
45+
}
46+
}

0 commit comments

Comments
 (0)