Skip to content

Listener

File extension: *.listener

Overview:

The *.listener files in the codbex platform are used to define listeners, which are event-driven components that respond to specific events or messages within the platform.

Here's an explanation of the example mylistener.listener file and its properties:

{
  "location": "/my-project/listeners/mylistener.listener",
  "name": "my-listener",
  "kind": "Q",
  "handler": "my-project/listeners/my-handler.js",
  "description": "My Listener",
  "createdBy": "admin",
  "createdAt": "2022-07-06T2:53:01+0000"
}

Properties:

  • location (String): Specifies the location or path of the listener file within the project. In this example, it is located at /my-project/listeners/mylistener.listener.
  • name (String): Represents the unique name or identifier of the listener. It is used to reference and identify the listener within the system. In this example, it is named my-listener.
  • kind (String): Indicates the kind or type of listener. The values are Q for a message queue listener and T for a message topic listener. This property helps the system understand the type of events the listener is designed to handle.
  • handler (String): Specifies the location or path of the script or module that serves as the listener handler. The handler contains the logic to be executed when an event is received. In this example, it is my-project/listeners/my-handler.js.
  • description (String): Provides a description of the listener, explaining its purpose or functionality. In this example, the description is "My Listener".
  • createdBy (String): Indicates the entity or user who created the listener. In this example, it is marked as admin.
  • createdAt (String): Represents the timestamp when the listener was created. The timestamp follows the ISO 8601 format. In this example, it is "2022-07-06T2:53:01+0000."

Example Usage:

The example mylistener.listener file defines a listener named my-listener that is designed to handle message queue events (kind: Q). The logic for handling events is implemented in the script located at my-project/listeners/test-handler.js.

Getting Started:

Create a Listener File:

Create a new *.listener file or modify an existing one based on your specific listener requirements.

Configure Listener Properties:

Adjust the properties within the file to match the details of your listener. Update the name, kind, handler, description, and other properties accordingly.

Implement Listener Handler Logic:

Create the associated module or script (e.g., my-project/listeners/my-handler.js) to provide the implementation logic for the listener. This script should contain the functionality you want to execute when an event is received.

Register and Trigger Events:

Register the listener within the platform, specifying the events or messages it should listen for. Trigger events or messages to test the listener's functionality.

Best Practices:

Clear Naming Conventions:

Follow clear and consistent naming conventions for listeners and their associated handlers.

Documentation and Comments:

Provide meaningful descriptions for listeners and document the purpose and usage of the associated handler. Additionally, add comments within the handler script to explain the implementation.

Conclusion:

The *.listener files in the codbex platform enable you to create event-driven components that respond to specific events or messages within the platform. Customize listeners based on your specific requirements, and leverage handlers to define the logic executed when events occur.