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

move to tokio, fix one broken example #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yjh0502
Copy link

@yjh0502 yjh0502 commented Oct 8, 2018

No description provided.

@zslayton
Copy link
Owner

zslayton commented Oct 9, 2018

Hi, thanks for the PR! Skimming through the diff, it looks like much more than fixing an example -- could you describe the changes you made and why they're important?

@yjh0502
Copy link
Author

yjh0502 commented Oct 9, 2018

The PR consists of two parts

  • Move from deprecated tokio-core[1] to tokio[2]. This is a main contribution of the PR.
  • Fix an example to demonstrate how to use updated API. After migrating from tokio-core to tokio, I tried to use updated API by myself. I started from examples, but found none of the examples are working. So I decided to fix an example to show how to use updated API.

[1] https://github.com/tokio-rs/tokio-core
[2] https://github.com/tokio-rs/tokio

@yjh0502
Copy link
Author

yjh0502 commented Oct 19, 2018

@zslayton Any update? If there's a problem, I'm willing to submit a new patch, for example removing tokio-coretokio migration and push examples only.

@zslayton
Copy link
Owner

@yjh0502 Sorry for the delay, I've been traveling for the last week. I'll get a chance to review this over the weekend.

src/session.rs Outdated
.as_mut()
.map(|t| t.poll())
.unwrap_or(Ok(Async::NotReady))?;
.unwrap_or(Ok(Async::NotReady))
.map_err(|_e| IoError::new(ErrorKind::Other, "timer"))?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with tokio_timer. Does it not provide an idiomatic return value to represent timeouts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two kinds of error, shutdown when there's no executor and at_capacity when timeout delay is too large to be handled (longer than 2 years in default timer).
tokio-timer has it's own error type, but it should be wrapped to std::io::Error because Session::Error is std::io::Error. We can change error string more specifically to help troubleshooting.

src/session.rs Outdated
@@ -468,7 +476,8 @@ impl Stream for Session {
let txh = self.state.tx_heartbeat_timeout
.as_mut()
.map(|t| t.poll())
.unwrap_or(Ok(Async::NotReady))?;
.unwrap_or(Ok(Async::NotReady))
.map_err(|_e| IoError::new(ErrorKind::Other, "timer"))?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question RE: an error type for timeouts.

@@ -0,0 +1,153 @@
extern crate env_logger;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is no longer its own subcrate, which I'm ok with but it makes it difficult to tell where the diffs are.

session: Session,
destination: String,
session_number: u32,

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra whitespace is unneeded.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it.

}
}

impl Future for ExampleSession {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stomp library has already changed its underlying implementation quite a few times. It's been singlethreaded, multithreaded, mio-based, tokio-core-based, and now tokio-based. It's not stable yet, so we can still make changes to the APIs. However, most of the changes in each migration have been implementation details. It's best if we don't require the end users of the API to change their code unless they have to.

In this example, the end user should only have to implement the methods on the Handler trait that they're interested in. If there's new, tokio-specific code that needs to be written for the Handler trait to work properly (for example, implementing Future), that should be an implementation detail handled by the library itself.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReceiptHandler/Handler is removed before I started to work on the library.

fb62a6e#diff-4c9ae8d0d599659f5476e14edb82cbaeL72

@yjh0502
Copy link
Author

yjh0502 commented Oct 22, 2018

Thanks for the review! I appended a commit to handle issues that addressed on the review.
BTW I'm adding more changes on my fork for my own needs, and you can see commit on following links: https://github.com/yjh0502/stomp-rs/commits/master

Primary goal of those changes is make stomp-rs usable on webassembly environment.

  • make session to accept custom IO struct (AsyncRead + AsyncWrite + Sync + 'static) other than TcpStream.
  • use handcrafted parser instead of nom, which does not work on wasm yet. I tried pest before moving to handwritten one, but It does not support non-utf8 input.
  • http style header API.
  • use rustfmt to normalize code format

I didn't sent a PR for those changes yet because I believe those changes are quite opiniated. How do you think of sending PR for those changes?

@jnicholls
Copy link

Sorry to hijack this PR thread, but is there an effort to get modern futures/tokio support for this library and is the work done to-date (including this PR) part of that effort? Or is the library mostly OBE?

@zslayton
Copy link
Owner

Hi, thanks for drawing my attention back to this PR. It had fallen off my radar. This PR is the only work happening on this library and I need to find the time to land it.

AFAIK there isn't another stomp library in wide use, so getting this one back up to speed with the ecosystem would be worthwhile.

@madbonkey
Copy link

It would seem to be still worthwhile :)

@jnicholls
Copy link

@madbonkey That it would! I guess STOMP is not a protocol in too much demand with those writing services in Rust.

@madbonkey
Copy link

madbonkey commented Feb 28, 2021

Seems true enough - I'd be happy to help out if there's something to do! A good library for STOMP would be nice to have, not so much for services/servers, but there's a lot of existing systems around using it and a robust client library would have an audience I think.

@zslayton
Copy link
Owner

zslayton commented Mar 2, 2021

Mea culpa. It's been very difficult to find bandwidth for this project. 😞 Apologies to @yjh0502 for neglecting this.

When I first created it I was using a variety of MQ servers at my day job and always had one lying around to test against. (Using STOMP was a nice cross-server compatibility option, and the protocol was much simpler to implement than AMQP.)

Tokio has reached 1.0 since this PR was first opened (again, my fault!). Is anyone interested in upgrading this to the stable version?

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.

4 participants