Invoking the SSE service

Accessing our new SSE forecast service is very simple. The SSE protocol uses the same underlying HTTP protocol as any other REST service; therefore, it can be invoked just like any other REST service. The only difference is that the response would be in a different format than JSON. You can quickly observe it when you invoke the service from a REST client, such as Postman, with a GET method at http://localhost:8080/forecast-service-async/smartcity/forecast.

Here is the result of invoking the Forecast service in Postman:

You can see that the response contains multiple chunks that contain data in JSON format. These represent all the SSE events sent by the service. Postman doesn't recognize them as events and waits until the response is complete. 

On the other hand, if you invoke the service using the curl command-line utility, which recognizes SSE events in the response, you will see a different behavior. 

When you invoke the curl utility from the command line, you'll see the following output:

> curl http://localhost:8080/forecast-service-async/smartcity/forecast
id: 1
data: {"forecast":{"location":{"name":"London"},"temperature":{"temperature":37.0,"temperatureScale":"CELSIUS"}},"processingTime":515}

id: 2
data: {"forecast":{"location":{"name":"Istanbul"},"temperature":{"temperature":44.0,"temperatureScale":"CELSIUS"}},"processingTime":1028}

id: 3
data: {"forecast":{"location":{"name":"Prague"},"temperature":{"temperature":44.0,"temperatureScale":"CELSIUS"}},"processingTime":1538}

id: completed
data: {}

The response will be in the same format, but the chunks for separate events will be printed immediately when they arrive, without waiting until the response is completed. This is because the cURL utility recognizes the "text/event-stream" media type of the response and understands the format of the response.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.159.223