pnxtech / hydra

A light-weight library for building distributed applications such as microservices
https://www.hydramicroservice.com
MIT License
645 stars 54 forks source link

fwsp-hydra examples #42

Closed linde12 closed 7 years ago

linde12 commented 7 years ago

Hello!

First things first, i think this is great! It's nice to have this package which bundles together the essentials for quick development of service-based applications!

However it would be great to see some examples of a real-world application.

Right now i'm kind of confused how hydra-express integrates with hydra. Some clarification with an example project would be lovely.

I'm also curious if there is a way to do RPC/request-response kind of communication with sendMessage/sendReplyMessage? What if i, on a GET /api/v1/login, want to communicate with another service before sending a response? How can i do this? I don't want the communication between the services to be available via a public API so i guess i can't use makeAPIRequest

I've just started using hydra and i'm eager to learn more about it in general so a simple example project would help a lot for everyone who wants to get involved i think.

emadum commented 7 years ago

Hi @linde12. I agree that a simple example project would be very helpful, and we'll be putting out some practical examples soon. In the meantime, I'd recommend checking out @cjus's tutorial if that isn't what brought you here.

You can definitely do some sort of RPC communication between services using sendMessage and sendReplyMessage - it's what we've been doing. Since all messages need to be JSON, I think it would be quite possible to use something like JSON RPC in the payload (body field) of the UMFMessages, but we haven't needed to implemented anything this robust so far.

IMO, you shouldn't feel that all HydraExpress services are public APIs. You can limit their accessibility at the application-level with auth, or at the system-level with firewall rules. We're doing both, and have plans to make our Hydra Express auth service open source eventually. This service uses JSON Web Tokens, and is just a light wrapper around fwsp-jwt-auth that checks passwords against our user database, and injects relevant user-data into the issued JWT.

However, an HTTP API is sometimes overkill, and there may be no reason to introduce the overhead of HTTP communication when you can use Redis pub-sub messaging. This is particularly true if these APIs are exclusively being consumed by other Hydra services.

HTH!

cjus commented 7 years ago

@linde12 I'm working on a post for RisingStack which will focus on hydra messaging using sendMessage and related functions. The article should be published around the end of this month. We'll let you know when that's available.

linde12 commented 7 years ago

@emadum Ah, yes i read that article. It was great and was what got me started. I see, but it's nothing that's built-in? To clarify what i want to do is something like this:

..., (req, res) => {
  hydra.sendMessage({to: 'service', from: 'another_service', bdy: {msg: 'Hello'}}, function onResponse (response) {
    res.send(response.bdy);
  });
});

@cjus That would be great, it's an important topic so some clarification would be great.

Again, great looking project. Can't wait to get started! :+1:

cjus commented 7 years ago

@linde12 here you basically need to use Hydra's hydra.on('message', function(message) {}) and hydra.sendMessage call. There's nothing yet to do this automatically. Join us on our fwsp-hydra@slack.com account to discuss this further with the team. Send me an email to cjus34@gmail.com and I'll send you an invite.

linde12 commented 7 years ago

@cjus Ah, i see! Sent you an email and closing this for now! Thanks!

aviyacohen commented 6 years ago

I am transfering this post to a new issue since I see the title of the issue and the actual substance are not the same.