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

feat: remove the reply filed support in operations #680

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/pages/function-lifecycle-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ Functions take a single argument, which is the event received from a broker or a
|channel|The name of the channel/topic from which the event was read.
|serverName|The name of the server/broker from which the event was received.

Functions may return an object to tell Glee what to do next. For instance, the following example greets the user back:
Functions may return an object to tell Glee what to do next. For instance, the following example sends a greeting message to `development` server:
```js
/* onHello.js */
export default async function (event) {
return {
reply: [{
send: [{
server: 'developement',
channel: 'greets',
payload: 'Greetings! How is your day going?'
}]
}
Expand All @@ -37,7 +39,7 @@ export default async function (event) {
|Attribute|Type|Description|
|---|---|---|
|send|array<[OutboundMessage](#anatomy-of-an-outbound-message)>|A list of outbound messages to send when the processing of the inbound event has finished. All clients subscribed to the given channel/topic will receive the message.
|reply|array<[OutboundMessage](#anatomy-of-an-outbound-message)>|A list of outbound messages to send as a reply when the processing of the inbound event has finished. This is useful when the target of your message is the sender of the inbound event. Note, however, that this only works when you're running Glee as a server. For example, using `reply` when receiving a WebSocket message is fine and the reply will exclusively go to the client that sent the message. However, if you're receiving a message from an MQTT broker, `reply` will work exactly the same way as `send` above, and will send the message to all the clients subscribed to the given channel/topic.
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting, reply is no more. it turned out to be obsolete. thanks for the update

Copy link
Member Author

Choose a reason for hiding this comment

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

it was cool to have it, you didn't have to specify the channel and the server that you sent the message to. but I think it's a source of confusion for now that we release version 1.0. this is something that we need for v2 of glee.


##### Anatomy of an outbound message
|Attribute|Type|Description|
|---|---|---|
Expand Down
10 changes: 2 additions & 8 deletions docs/pages/glee-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ operations:
action: receive
channel:
$ref: '#/channels/hello'
reply:
channel:
$ref: "#/channels/hello"
SendHello:
action: send
channel:
Expand Down Expand Up @@ -73,9 +70,6 @@ operations:
action: receive
channel:
$ref: '#/channels/hello'
reply:
channel:
$ref: "#/channels/hello"
sendHello:
action: send
channel:
Expand All @@ -84,8 +78,8 @@ operations:

The channels section defines the communication channels available in the API. In this case, there's a channel named "hello". This channel supports both sending and receiving.

The `receive` action indicates that messages received on the `hello` channel should follow the structure defined in the hello message component. Under this action, `reply` which is in a request-reply operation, contains the payload on `onHello.js` function.
The `send` action specifies that the operation with ID `sendHello` is used for sending messages to the `hello` channel. The message structure is referenced from the hello message component.
The `receive` action indicates that messages received on the `hello` channel should follow the structure defined in the hello message component.
The `send` action specifies that the operation with ID `sendHello` is used for sending messages to the `hello` channel. The message structure is referenced from the hello message component. The message payload is going to be validated against the `sendHello` operation message schemas.

Next is the `payload` property under `hello` message component which is used to understand how the event should look like when publishing to that channel:

Expand Down
7 changes: 3 additions & 4 deletions docs/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ operations:
action: receive
channel:
$ref: '#/channels/greet'
reply:
channel:
$ref: '#/channels/greet'
sendGreet:
action: send
channel:
Expand Down Expand Up @@ -127,8 +124,10 @@ export default async function (event) {
response = `Good Evening ${name}`
}
return {
reply: [
send: [
{
server: "websockets",
channel: "greet"
payload: response,
},
],
Expand Down
7 changes: 3 additions & 4 deletions docs/pages/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ operations:
action: receive
channel:
$ref: '#/channels/hello'
reply:
channel:
$ref: "#/channels/hello"
SendHello:
action: send
channel:
Expand All @@ -121,7 +118,9 @@ Create an operation function `onHello.js` inside `myapp/functions`:
```js
export default async function (event) {
return {
reply: [{
send: [{
server: "websockets",
channel: "hello",
payload: `Hello from Glee! You said: "${event.payload}".`
}]
}
Expand Down
52 changes: 50 additions & 2 deletions examples/dummy/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
# Dummy
## Introduction

This is a dummy example mainly used to test functionalities.
This project is an example websocket-based application that simulates email sending and forwards messages to a Mosquitto server. It's a great example of real-time data handling and integration with MQTT protocol.

## Getting Started

### Installation

To set up the project, follow these simple steps:

1. Clone the Glee repository to your local machine.
2. Navigate to the project directory (examples/dummy).
3. Run the following command to install all the required dependencies:

```bash
npm i
```

### Running the Project

After installing the dependencies, you can start the project by running:

```bash
npm run dev
```

This will start the development server on `localhost:3005`.

## Making a WebSocket Connection

To interact with the WebSocket server, you can use a WebSocket client like [websocat](https://github.com/vi/websocat). Here's how you can connect and send a message:

1. Open a terminal and connect to the WebSocket server using the following command:

```bash
websocat ws://localhost:3005/user/signedup
```

2. Once connected, you can send a message in JSON format. For example:

```json
{"displayName": "John Doe", "email": "[email protected]"}
```

## Behind the Scenes

When you send a message:

- The `receiveUserSignedUp` function is triggered.
- The application simulates sending an email to the provided email address.
- It then forwards the message to the Mosquitto server at `test.mosquitto.org`.
31 changes: 14 additions & 17 deletions examples/dummy/asyncapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ servers:
bindingVersion: 0.2.0
websockets:
host: 'localhost:3005'
pathname: /ws
protocol: ws
channels:
user/signedup:
address: user/signedup
userSignedUp:
address: /user/signedup
messages:
onUserSignedUp.message:
$ref: '#/components/messages/UserSignedUp'
subscribe.message:
UserSignedUp:
$ref: '#/components/messages/UserSignedUp'
bindings:
ws:
Expand All @@ -43,35 +40,35 @@ channels:
my-custom-header:
type: string
const: custom value
server/announce:
serverAnnounce:
address: server/announce
messages:
subscribe.message:
ServerAnnounce:
$ref: '#/components/messages/ServerAnnounce'
operations:
onUserSignedUp:
recieveUserSignedUp:
action: receive
channel:
$ref: '#/channels/user~1signedup'
$ref: '#/channels/userSignedUp'
bindings:
mqtt:
qos: 2
retain: true
bindingVersion: 0.2.0
messages:
- $ref: '#/components/messages/UserSignedUp'
user/signedup.subscribe:
- $ref: '#/channels/userSignedUp/messages/UserSignedUp'
sendSignedUpUser:
action: send
channel:
$ref: '#/channels/user~1signedup'
$ref: '#/channels/userSignedUp'
messages:
- $ref: '#/components/messages/UserSignedUp'
server/announce.subscribe:
- $ref: '#/channels/userSignedUp/messages/UserSignedUp'
sendServerAnnounce:
action: send
channel:
$ref: '#/channels/server~1announce'
$ref: '#/channels/serverAnnounce'
messages:
- $ref: '#/components/messages/ServerAnnounce'
- $ref: '#/channels/serverAnnounce/messages/ServerAnnounce'
components:
securitySchemes:
userAndPassword:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export default async function (event) {
const user: any = event.payload
console.log(`${user.displayName} has recently signed up. Sending an email to ${user.email}.`)
// Send an email to the user here

return {
send: [{
server: 'websockets',
server: 'mosquitto',
channel: 'userSignedUp',
payload: event.payload,
}]
}
Expand Down
15 changes: 0 additions & 15 deletions examples/dummy/glee.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import fs from 'fs'

export default async function () {
return {
glee: {
logs: {
incoming: 'channel-only',
outgoing: 'channel-only'
}
},
docs: {
enabled: false
},
Expand All @@ -21,14 +15,5 @@ export default async function () {
}
}
}
// websocket: {
// httpServer: customServer,
// adapter: 'native', // Default. Can also be 'socket.io' or a reference to a custom adapter.
// },
// cluster: {
// adapter: 'redis',
// name: 'gleeCluster',
// url: 'redis://localhost:6379'
// }
}
}
2 changes: 1 addition & 1 deletion examples/dummy/lifecycle/announceServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default async function () {
return {
send: [{
server: 'mosquitto',
channel: 'server/announce',
channel: 'serverAnnounce',
payload: {
id: process.env.SERVER_ID || String(Date.now()),
}
Expand Down
38 changes: 19 additions & 19 deletions examples/dummy/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions examples/slack-reaction-listener/asyncapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,7 @@ operations:
$ref: "#/channels/OpenAICompletion"
messages:
- $ref: "#/channels/OpenAICompletion/messages/OpenAICompletionResponse"
reply:
channel:
$ref: "#/channels/SlackPostMessage"
HandleSlackReaction:
reply:
channel:
$ref: "#/channels/SlackEventStream"
messages:
- $ref: "#/channels/SlackEventStream/messages/slackAckEvent"
action: receive
channel:
$ref: "#/channels/SlackEventStream"
Expand Down
6 changes: 3 additions & 3 deletions examples/slack-reaction-listener/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading