Create Eventsource plugins
Godspeed has a plugin based ecosystem and you can install the plugins using CLI. Now let us understand how can you contribute a plugin.
In this section, let us understand how a developer can contribute a plugin to godspeed plugin repo or for internal use. Follow these step-by-step guidelines to receive detailed instructions on contributing your plugin.
Steps to create new plug-in in our godspeed framework:
Begin by installing the
godspeed-plugin-generator
globally using the following commands:npm install -g generator-godspeed-plugin
npm install -g yoTo initiate the creation of your plugin, execute the following command in your terminal:
yo godspeed-plugin
After running the above command, you'll be prompted to enter your desired plugin name. Proceed by typing it in:
? Enter your plugin name: (your-plugin-name)
Select the type of plugin that aligns with your project's requirements. You can choose from the following options:
? Select the type of plugin: (Use arrow keys)
❯ DataSource
EventSource
DataSource-As-EventSource⚠️ Note: In certain network environments, particularly on WiFi connections, you may encounter a
Request failed with status code 403
error due to network security protocols or firewall restrictions that block specific API requests. To bypass this limitation, consider switching to a mobile data hotspot, which often has fewer restrictions. This workaround can help ensure successful command execution and avoid network-related request failures.Depending on your selection, the plugin generator will generate a template with your chosen plugin name, such as "your-plugin-name-as-datasource." The structure of the generated files will be as follows:
.
├── src
| └── index.ts
|
├── package.json
|
├── README.md
|
├── tsconfig.json
|
├── .gitignore
|
└── .npmignoreTo customize your plugin, navigate to the
index.ts
file located in thesrc
directory. You can modify the content within this file to meet your specific plugin requirements. There's no need to make changes to any other files outside ofindex.ts
.
If you opt for EventSource
, the index.ts
file appears as follows:
import { PlainObject, GSActor, GSCloudEvent, GSStatus, GSEventSource, GSDataSource, GSContext } from "@godspeedsystems/core";
class EventSource extends GSEventSource {
protected initClient(): Promise<PlainObject> {
// initialize your client
}
async subscribeToEvent(eventRoute: string, eventConfig: PlainObject, processEvent: (event: GSCloudEvent, eventConfig: PlainObject) => Promise<GSStatus>): Promise<void> {
try {
// subscribeToEvent
} catch (error) {
throw error;
}
}
}
const SourceType = 'ES';
const Type = "p"; // this is the loader file of the plugin, So the final loader file will be `types/${Type.js}`
const CONFIG_FILE_NAME = "p"; // in case of event source, this also works as event identifier, and in case of datasource works as datasource name
const DEFAULT_CONFIG = {};
export {
EventSource,
SourceType,
Type,
CONFIG_FILE_NAME,
DEFAULT_CONFIG
}
If you opt for DataSource-As-EventSource
, the index.ts
file appears as follows:
import { GSContext, GSDataSource, PlainObject, GSDataSourceAsEventSource, GSCloudEvent, GSStatus, GSActor} from "@godspeedsystems/core";
class DataSource extends GSDataSource {
protected async initClient(): Promise<PlainObject> {
try {
// initialize your client
} catch (error) {
throw error;
}
}
async execute(ctx: GSContext, args: PlainObject): Promise<any> {
try {
// execute methods
} catch (error) {
throw error;
}
}
}
class EventSource extends GSDataSourceAsEventSource {
async subscribeToEvent(
eventKey: string,
eventConfig: PlainObject,
processEvent: (
event: GSCloudEvent,
eventConfig: PlainObject
) => Promise<GSStatus>
): Promise<void> {
// subscribeToEvent
}
}
const SourceType = 'BOTH';
const Type = "shirisha"; // this is the loader file of the plugin, So the final loader file will be `types/${Type.js}`
const CONFIG_FILE_NAME = "shirisha"; // in case of event source, this also works as event identifier, and in case of datasource works as datasource name
const DEFAULT_CONFIG = {};
export {
DataSource,
EventSource,
SourceType,
Type,
CONFIG_FILE_NAME,
DEFAULT_CONFIG
}
For better understanding checkout Examples and watch following videos
AWS (DataSource)
CRON (EventSource)
KAFKA (DataSource-As-EventSource)
How to create plugins using godspeed?
Here is a video which helps you create a plugin using the godspeed. Do watch for better understanding
Create and use plugins using godspeed
Watch here the video where we demonstrate how to create and use plugins using godspeed.