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

Is In-Memory communication channels supported? #2100

Open
mauroa opened this issue Nov 4, 2024 · 5 comments
Open

Is In-Memory communication channels supported? #2100

mauroa opened this issue Nov 4, 2024 · 5 comments

Comments

@mauroa
Copy link

mauroa commented Nov 4, 2024

The documentation mentions it: Extensible communication channels (e.g. In-Memory, TCP, TCP+TLS, WS), however I'm not sure if this is really supported and how I should configure it.

I ask this in order to avoid the firewall prompt to allow opening a TCP port when starting the MQTT server, in cases where the MQTT connection and messages exchange will be performed in-process.

Thanks

@wellsjiang
Copy link

I had this requirement a year ago, but after reviewing the documentation and issues, I found that MQTTnet does not provide a ready-to-use in-memory communication channel. It needs to be implemented manually. I’m not sure if this feature is available now. If it is still not provided, implementing this feature is quite easy. You just need to implement IMqttClientAdapterFactory, IMqttChannel, and IMqttServerAdapter.

@mauroa
Copy link
Author

mauroa commented Nov 7, 2024

Thanks for your response. I did exactly that, since I noticed that it's not really supported. I have a working in-memory version now.
The trickiest part was to synchronize the memory stream of the channels to read/write correctly. Did you use another alternative than a MemoryStream to accomplish it?
Thanks

@sebastian-dev
Copy link

@mauroa
can you upload a small sample client/server with your implementaion.
have you benchmarked the connection: local TCP vs inMemmory.
Have you seen a significant improvement in performance or memory consumption?

@mauroa
Copy link
Author

mauroa commented Nov 15, 2024

I'm attaching a simple console app that I made with the in-memory support. It uses MemoryStream and a series of thread synchronization and lock mechanisms to allow reading and writing correctly in both client and server sides, given the nature of the MemoryStream.

If you find improvements to make, please let me know.

TestMQTTnet.zip

@CZEMacLeod
Copy link
Contributor

Would this be easier to implement using System.IO.Pipelines? - My understanding is it is designed for this kind or scenario.

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

No branches or pull requests

4 participants