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

💝 Event receiver & stream via Server-Sent Events #11

Merged

Conversation

cardil
Copy link
Member

@cardil cardil commented Mar 7, 2023

Fixes SRVCOM-2287

Changes

  • 💝 Event receiver & stream via server-sent events
  • 🎁 React+Typescript frontend app
  • 🧹 Simplified build

Explanation

The UI was extracted from both backends (they had used server-side rendering before), into a separate React app written in Typescript.

This React app is now built into a set of static files, which are packaged as a webjar for easy consumption on both backends (especially in the Java one). The frontend application, of course, can be started in development mode, either running on stubs, or connecting to the real backend.

Both backends have the event receiver implemented at POST /events. Both backends have the Server-Sent Events (SSE) endpoint implemented at GET /events. You can connect to it in streaming mode using tools like HTTPie (the connection will be left hanging, and any new events will be delivered to the client, CloudEvents are encoded as structured):

$ http :8080/events
HTTP/1.1 200 OK
Content-Type: text/event-stream
X-SSE-Content-Type: application/cloudevents+json
transfer-encoding: chunked

data:{
    "data": {
        "greeting": "Welcome",
        "number": 94,
        "who": "Developer82"
    },
    "datacontenttype": "application/json",
    "id": "38d021ba-db7b-67df-98e9-e1a3be37ca53",
    "source": "//devdata",
    "specversion": "1.0",
    "time": "2023-02-10T07:33:55+01:00",
    "type": "com.redhat.openshift.knative.showcase.hello.Hello"
}

The React frontend have also the dedicated UI component that connects to that event stream and presents it in a nice table:

Screenshot from 2023-03-14 11-04-45

Related issues

During the developments I've stumbled on a number of upstream issues, I needed to work around:

/kind enhancement

@cardil cardil marked this pull request as ready for review March 13, 2023 19:36
@openshift-ci openshift-ci bot requested review from mgencur and pierDipi March 13, 2023 19:36
Copy link
Member Author

@cardil cardil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A self-review 😼

.github/workflows/container-build.yaml Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
expressjs/README.md Outdated Show resolved Hide resolved
frontend/src/events/u-cloudevents.ts Outdated Show resolved Hide resolved
quarkus/src/main/templates/application.properties Outdated Show resolved Hide resolved
expressjs/src/routes/events/endpoint.js Show resolved Hide resolved
@cardil cardil changed the title 💝 Event receiver & stream via SSE 💝 Event receiver & stream via Server-Sent Events Mar 14, 2023
README.md Show resolved Hide resolved
@cardil
Copy link
Member Author

cardil commented Mar 14, 2023

/cc @mgencur
/cc @jrangelramos
/cc @pierDipi
/cc @rhuss
/cc @matzew

Copy link

@mgencur mgencur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cardil , thanks for implementing the new features. I have only tested one part of it (the frontend which sends evens repeatedly) but I have a left a number of comments.

This application is named "OpenShift Knative Showcase" or "Knative Showcase" and it mentions Knative in many places. It also says it "showcase the Knative features".
For me, this application shows sending and receiving CloudEvents in a nice way. It can be used side-by-side with Knative Eventing to show events that are sent/received. But it doesn't have/show Knative features. So, mentioning "Knative" all over the place is misleading at this point.
I don't know what will be the future of this application. Do you have any plans for functionality that would demonstrate Knative features?
Thanks

expressjs/README.md Show resolved Hide resolved
frontend/src/index/stub.ts Show resolved Hide resolved
Makefile Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
expressjs/src/routes/info/endpoint.js Show resolved Hide resolved
frontend/README.md Outdated Show resolved Hide resolved
@cardil
Copy link
Member Author

cardil commented Apr 12, 2023

I have only tested one part of it (the frontend which sends evens repeatedly)

Well, this frontend app, by in development mode, by default work on stubs. Those stubs simulate receiving events continuously. But, that's just a simulation.

This application is named "OpenShift Knative Showcase" or "Knative Showcase" and it mentions Knative in many places. It also says it "showcase the Knative features". For me, this application shows sending and receiving CloudEvents in a nice way. It can be used side-by-side with Knative Eventing to show events that are sent/received. But it doesn't have/show Knative features. So, mentioning "Knative" all over the place is misleading at this point.

The eventing bits (event receive, and streaming) are just coming in this PR. This app already has a number of features that's helpful to showcase Serving functionality.

Have you seen the README? Especially after the changes in this PR (a little cleanup). There are a couple of things that help showcase Serving:

  • fast app boot (requirement for Serving scale from zero),
  • support for $PORT (automatically set by Serving),
  • support for $DELAY (to help showcase scaling),
  • support for $GREET (to help showcase traffic distribution, as different revisions will have different output)

Also, already in, is the sending of the event to the $K_SINK, which obviously helps to showcase Eventing, especially the SinkBinding.

So, I think this app already helps showcase Knative features, and this PR only adds to that.

@cardil cardil requested a review from mgencur April 12, 2023 21:02
@mgencur
Copy link

mgencur commented Apr 13, 2023

/lgtm
/approve

@openshift-ci
Copy link

openshift-ci bot commented Apr 13, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cardil, mgencur

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit a01a18c into openshift-knative:latest Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants