Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for connection and subscription headers #2

Closed
wants to merge 2 commits into from

Conversation

snaggen
Copy link

@snaggen snaggen commented Jun 16, 2022

This is a first draft at supporting connection and subscription headers, to be able to use the ActiveMq stomp extentions
https://activemq.apache.org/stomp

Not sure about having both connect and connect_with_headers, but I didn't want to add them to the regular connect function since the headers are a corner case. Same with subscribe.

Also the to_client_msg will always have empty headers, just like for the Send... not sure how correct this is.

So, please have a look and see what you think.

Copy link

codecov bot commented Jan 2, 2024

Codecov Report

Attention: Patch coverage is 76.66667% with 35 lines in your changes missing coverage. Please review.

Project coverage is 67.31%. Comparing base (8bc7416) to head (487c0d5).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/client.rs 74.26% 35 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #2      +/-   ##
==========================================
+ Coverage   59.86%   67.31%   +7.45%     
==========================================
  Files           3        3              
  Lines         578      716     +138     
==========================================
+ Hits          346      482     +136     
- Misses        232      234       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@snaggen
Copy link
Author

snaggen commented Jan 2, 2024

I have ported this to the latest main branch, and removed the _with_headers functions by using builders instead.
Not sure how to improve coverage, since tests requires a server.
But, let me know what you think about the builder approach

@snaggen snaggen changed the title WIP: Add support for connection and subscription headers Add support for connection and subscription headers Jan 2, 2024
@snaggen
Copy link
Author

snaggen commented Jan 2, 2024

Maybe @zuisong have an opinion on this? Is this something that is generally desirable, or is it just a weird corner case feature? And is builders better or worse than adding another connect_with_headers method?

@zuisong
Copy link
Contributor

zuisong commented Jan 2, 2024

let connect = Message {
    content: ToServer::Connect {
        accept_version: "1.2".into(),
        host: virtualhost,
        login,
        passcode,
        heartbeat: None,
        headers, //<-- header at here
    },
    extra_headers: vec![], //<-- header appear again
};

Message<*> was designed to support extra_headers, no need to add headers property in each enum.


If you want to increase the test coverage, one possible solution is to use testcontainers , which starts an stomp server during the tests

@snaggen
Copy link
Author

snaggen commented Jan 2, 2024

Thanks for the reply, I will have a look into this

@snaggen snaggen force-pushed the connect_subscribe_headers branch from 4437440 to a6615fd Compare January 4, 2024 11:13
@snaggen
Copy link
Author

snaggen commented Jan 4, 2024

@zuisong I now use the extra_headers field, by letting the Message to_frame method add the extra headers if they are not already present in the frame.
I also did a rebase and squashed all commits in to one.

@zuisong
Copy link
Contributor

zuisong commented Jan 5, 2024

I don't have any other questions.

To increase coverage, you can try doing this.

diff --git a/Cargo.toml b/Cargo.toml
index a68113d..9582438 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,3 +23,7 @@ typed-builder = "0.18.0"
 
 [dev-dependencies]
 tokio = { version = "1", features = ["time", "macros", "rt-multi-thread"] }
+testcontainers = { version = "0.15" }
+
+[features]
+integration-test = []
diff --git a/src/client.rs b/src/client.rs
index f9e4195..e5635c6 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -331,3 +331,40 @@ fn connection_message() {
 
     assert_eq!(expected_buffer, actual_buffer);
 }
+
+#[cfg(feature = "integration-test")]
+#[cfg(test)]
+mod integration_test {
+
+    use std::net::Ipv4Addr;
+    use testcontainers::{core::WaitFor, clients, GenericImage};
+    use crate::client;
+
+    #[tokio::test]
+    async fn test_connect() {
+        let docker = clients::Cli::default();
+        let activemq = docker.run(
+            GenericImage::new("apache/activemq-artemis", "latest-alpine").with_wait_for(
+                WaitFor::StdOutMessage {
+                    message: "0.0.0.0:8161".into(),
+                },
+            ),
+        );
+        dbg!(&activemq.ports());
+
+        let stomp_port = activemq.ports().map_to_host_port_ipv4(61613).unwrap();
+        dbg!(stomp_port);
+
+        // now you got stomp server at 127.0.0.1:${stomp_port}
+
+        //  write your test here
+        let mut conn = client::connect(
+            (Ipv4Addr::LOCALHOST, stomp_port),
+            "/".to_string(),
+            "artemis".to_string().into(),
+            "artemis".to_string().into(),
+        )
+        .await
+        .unwrap();
+    }
+}

@snaggen
Copy link
Author

snaggen commented Jan 5, 2024

Well, I increased the coverage already, so I think the testcontainer is a bit overkill. But, it is good to have in mind if we really want to test the last pieces of the code. But, I leave that to @alexkunde to do that.

@snaggen
Copy link
Author

snaggen commented Oct 29, 2024

Closing due to inactivity and this is included in my async-stomp fork

@snaggen snaggen closed this Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants