pnxtech / hydra-cli

Hydra Command Line Client
MIT License
12 stars 9 forks source link

$ hydra-cli rest hello-service:[get]/ #37

Closed sanjeevgehlot008 closed 3 years ago

sanjeevgehlot008 commented 6 years ago

When I am running this command, I am getting following error:

command : $ hydra-cli rest gateway-service:[get]/ output : Cannot read property 'toString' of undefined

cjus commented 6 years ago

@sanjeevgehlot008 can you confirm that the gateway-service:[get]/ returns a valid JSON output. What happens when you access the above via a web browser?

sanjeevgehlot008 commented 6 years ago

Yes it is working on browser, when I run this, http://localhost:41737/v1/gateway

Output is : {"statusCode":200,"statusMessage":"OK","statusDescription":"Request succeeded without error","result":{"greeting":"Welcome to Hydra Express!"}}

cjus commented 6 years ago

@sanjeevgehlot008 I should have asked you this earlier, but what OS and version of NodeJS are you using with Hydra-cli? Also, how does your gateway service send back the above response? What I'm wondering here is whether the response contains an HTTP Content-Type: application/json header field.

sanjeevgehlot008 commented 6 years ago

OS "is Windows 10 Education" and Node Version is "v8.9.3". I follow your youtube video : https://www.youtube.com/watch?v=dHFQxrc4Fnk and did same as you said in above video. But hydra-cli is giving error as I said above. gateway-service is just like red-service(from your videos). Also, when I am running blue service seperately, its working fine, but when I am using below code in gateway-service to get response from blue-service, I am getting 'Service-Unavailable'.

Request : let message = hydra.createUMFMessage({ to: 'blue-service:[get]/v1/blue/', from: 'gateway-service:/', body: {}
}); hydra.makeAPIRequest(message) .then((response)=>{ console.log('response', response); });

Response : response { statusCode: 503, statusMessage: 'Service Unavailable', statusDescription: 'The server is currently unable to handle the request due to a temporary overloading or maintenance of the server', result: { reason: 'Unavailable blue-service instances' } }

arn-the-long-beard commented 6 years ago

Hello @sanjeevgehlot008 ,

I am following this tutorial https://community.risingstack.com/tutorial-building-expressjs-based-microservices-using-hydra/

And I also have the same error as you. I also have the error if I follow this one https://www.hydramicroservice.com/docs/quick-start/step3.html

cjus commented 6 years ago

@arn-the-long-beard thanks. we'll get to the bottom of this! @sanjeevgehlot008 or @arn-the-long-beard can you post your related config.json files?

sanjeevgehlot008 commented 6 years ago

config.json (gateway-service)

{ "environment": "development", "hydra": { "serviceName": "gateway-service", "serviceIP": "", "servicePort": 0, "serviceType": "gateway", "serviceDescription": "gateway", "redis": { "url": "127.0.0.1", "port": 6379, "db": 15 } } }

config.json (blue-service)

{ "environment": "development", "hydra": { "serviceName": "blue-service", "serviceIP": "", "servicePort": 0, "serviceType": "blue", "serviceDescription": "blue", "redis": { "url": "127.0.0.1", "port": 6379, "db": 15 } } }

cjus commented 6 years ago

@sanjeevgehlot008 can you zip up your project - minus the node_modules folder and drag and drop it into the chat window below? - I think it will just easiest if I run your exact sample locally. ;-)

arn-the-long-beard commented 6 years ago

Hello :)

Here is my config

{
  "hydra": {
    "serviceName": "hello",
    "serviceIP": "localhost",
    "servicePort": 3010,
    "serviceType": "",
    "serviceDescription": "Says hello",
    "redis": {
      "url": "127.0.0.1",
      "port": 6379,
      "db": 15
    }
  }
}

You can actually use the package from this tutorial

https://community.risingstack.com/tutorial-building-expressjs-based-microservices-using-hydra/

JeraldAEvans65 commented 5 years ago

I had the same problem, this issues is with the example: api.get("/", function(req, res) { res.send({ <- this is an object with key value msg: hello from ${hydra.getServiceName()} - ${hydra.getInstanceID()} }); }); hydraExpress.registerRoutes({ "": api }); }

change to: res.send( hello from ${hydra.getServiceName()} - ${hydra.getInstanceID()});