-
Notifications
You must be signed in to change notification settings - Fork 19
Documentation on how to connect transportbus of 2 go applications #51
Comments
Hi Patrick, Thank you so much for your interest. It completely slipped off my radar for me to document how to establish a connection between two Plank-based applications. I already wrote some example code to demonstrate how to talk to different brokers but it is missing detailed instructions on how to actually do that. Let me get back to it and do my best at writing a full end-to-end guide so you can follow along. Will get back soon to you! Thanks, |
Hi Josh Thanks for answering so soon. I would be happy to help with the documentation and provide a PR... Thanks and have a nice weekend |
I would love contributions from you, so let me write some proof of concept of what you want to achieve and will share a branch with you. I have a bit of a packed day today for my primary responsibilities so I may be able to work on it toward the end of day or later time permitting, but I will get to you very soon! |
In the meantime, you could check out the examples at https://github.com/vmware/transport-go/tree/main/plank/cmd/broker_sample/plank if you have not checked it out. These examples showcase how to talk to another Plank instance either by WebSocket or TCP. If you opt to use TCP, make sure to update the value for key |
It getting late here in Europe (and weekend)... config.json? Most of my test where using WS not TCP (mostly because I felt that WS would leave more options open -- not to speak of less trouble with the security/firewall team). Does plank need server side code or just correct config? |
I think I now have better context. I see you may have used Plank without a configuration file. The config.json file I mentioned is a single source of truth for configuring and tweaking the behaviors of Plank such as WebSocket endpoints, TLS, etc. If you followed the Hello World guide for Plank exactly as-is, you already have an HTTP server (with a self-signed cert) running with WebSocket endpoint at URI /ws. I may have gaps in understanding your setup and actual commands you used to start Plank, but I would love to hear in detail what you are trying to achieve and help you achieve it, so if you can tell me how you tried the example code and what behaviors you got, that would be greatly helpful for me. In the meantime, here's what you can do because as you said it's already late for you and you may not want me to eat up into your precious weekend :) Once you have started the sample by following the guide above (up to the point of running WS_USE_TLS=1 LISTEN_METHOD=plank_ws go run cmd/broker_sample/app.go Example
If everything went successfully, you'll see a message payload that originated from the Plank server that you started earlier. This essentially demonstrates how you can talk to other Plank or any STOMP servers (with the details in |
This did not leave my mind at peace... Everything works as you described. I hacked together some sample code (I know it is not running): var ( func main() { func handler(name string) {
} What I would like to do is move handler("1") and handler("2") into separate binaries. But this can wait 'till Monday. Have a nice weekend. |
Thanks for providing a code sample! The "app.go" app is merely a client, so it does not have any capabilities to respond to incoming requests, so starting it twice basically emulates a single server serving two clients. In the context of what you are trying to achieve - two individual services talking to each other, therefore, it is not a good example. I think this would be best explained if I drew up a diagram to explain some concepts and how all things fit together (e.g. where Plank comes into play that connects two channels each from different processes). So stay tuned! |
In the meantime, so what you need is two Plank apps (let's call Plank A and Plank B) each running their own Transport bus instances. Then this piece of code bridges Plank A's local channel to Plank B's channel representing the service you're trying to reach. In actuality, you would likely write a service like this and manage the connection state for the other service as a long-running goroutine. (Obviously it'll have to be much better than over_ws.go obviously) |
Here's my quick take at visualizing what I explained above (excuse my handwriting 🤣) |
Thanks for your help. Right now I do not see my mistake (unless it was only the missing subscribe), but I asked my boss to get authorisation to put some of my code on github to illustrate what I want to do... I am not sure how far I'll get today so let me give you some background meanwhile: Most of my event will just be received and processed by a (potentially unknown number) of consumers, some of those will just use it locally others will generate new events. There will (potentially) be 3 types of connections:
Right now I am doing this:
} |
Thanks for your response Patrick. I see that you have used the packages mostly in the correct way! But as you may have noticed writing that code, is is very verbose and requires extensive boilerplate code which could easily become unwieldy. Such boilerplating and plumbing work is handled by a "service" that comes handy with Plank. I took this evening to write an example service that demonstrates cross-process communication in my WIP PR - #52. You can check out this PR's branch and inspect the service code and run each server app server_one and server_two as shown below: In one terminal, cd plank/cmd/cross_plank_communication/server_one
go run server_one.go --config-file config.json In another, cd plank/cmd/cross_plank_communication/server_two
go run server_two.go --config-file config.json Make sure to start server_one first, otherwise you'll see during server_two startup an error message that it could not start the service. After both servers are up, after five seconds, you'll see some debug messages printed out to the terminal for server_two. The example code demonstrates all the logic you wrote above, but does so in a service-like fashion where the actual business code is decoupled from the plumbing work (which Plank does for you). You still have to maintain the WebSocket connection as part of your business code (which is why the broker connection logic is part of the service code), and I left some comments throughout the code that may help you think about how best to handle the WS lifecycle. Feel free to check it out, compare it with the use cases you need to achieve and let me know if you have further questions, happy to help! |
Thanks a lot for your work! This helps a lot! I completely agree with you about the boilerplate code and would like to take it even further. What do you think about global channels get transparently replicated among the connected buses? In my earlier code example it would look like: It would transparently connect to (or start) a broker that connects the global channels of different bus instances. |
I managed to get permission to opensource my bus code: The example show pretty much how my code uses transport bus. goroutine 77 [running]: It does not matter if I use /topic or /pub/queue/ and /queue. |
Hi Josh Thanks a lot for your help and time. Thanks and enjoy the weekend, |
Hi Patrick, Sorry I was not able to assist you in time, as my main responsibilities bogged me down with getting back to you. Appreciate your spending time with me! I'm sure the panic you got has to do with either one of the bus channels or other constructs being nil, but for the sake of my own investigation and potentially letting you know I will review your code and why the panic happens if it's ok with you. Thanks again, and have a happy weekend as well! Josh |
Hi Josh I really appreciate the time you spent with me! It helped me a lot and I learned new things about message buses. All the best |
Is your feature request related to a problem? Please describe.
Hi
In the documentation it is mentioned that it is quite easy to connect 2 instances of transport-bus.
Unfortunately I was not able to figure how to do it...
I was try in with MarkChannelAsGalactic and StartFabricEndpoint as well as with plank.
Otherwise I am quite happy with transport-bus and how it works...
Have fun
Patrick
Describe the solution you'd like
Some code explaining how to do it...
Describe alternatives you've considered
Writing it myself.
Additional context
No response
The text was updated successfully, but these errors were encountered: