- Notifications
You must be signed in to change notification settings - Fork3
sameerajayasoma/app-gateway
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A gateway is a service designed to manage and improve traffic to and from web applications and apis by performing various functions such as load balancing, SSL/TLS offloading, security, traffic shaping, and caching.
This repository includes a sample gateway written in Ballerina that can be customized to route and handle one or more applications and apis. Additionally, it offers the capability to execute policy agents for each request and response, which can be configured as plugins within the gateway. This enables fine-grained control over traffic and the enforcement of policies based on specific attributes of each request and response.
You need to use Ballerina 2201.5.0 (Swan Lake Update 5) or higher version to run the program.
% cd gateway% bal pack;bal push --repository=local% cd ../xyz-gateway% bal runCompiling source xyz/xyz_gateway:0.1.0Running executableTry out the gateway with following sample commands.
curl localhost:9090/api/xyz-entitlement-service/curl localhost:9090/api/xyz-entitlement-service/metricscurl localhost:9090/api/xyz-navbarcurl localhost:9090/app/xyz-resource-cachegateway- directory contains theballerinax/gatewaylibrary package.xyz-gateway- directory contains a sample gateway written usingballerinax/gatewaylibrary.
importballerinax/gateway;importballerina/http;http:ListenerConfigurationlistenerConfig= {};listenerhttp:ListenerhttpListener=checknew (9090,listenerConfig);publicfunction main()returnserror? {gateway:registerPlugin(PLUGIN_ID_ADD_ACCESS_TOKEN,pluginConfig =>newAddAccessTokenPlugin(pluginConfig));gateway:registerPlugin(PLUGIN_ID_ADD_HEADERS,pluginConfig =>newAddHeadersPlugin(pluginConfig));gateway:registerPlugin(PLUGIN_ID_CORS_HEADERS,pluginConfig =>newCORSHeaderPlugin(pluginConfig));gateway:registerPlugin(PLUGIN_ID_NETWORK_CONTROL,pluginConfig =>newNetworkControlPlugin(pluginConfig));gateway:registerPlugin(PLUGIN_ID_REMOVE_HEADERS,pluginConfig =>newRemoveHeadersPlugin(pluginConfig));gateway:registerPlugin(PLUGIN_ID_ALWAYS_ABORT_PLUGIN,pluginConfig =>newAlwaysAbortPlugin(pluginConfig));checkgateway:'start(httpListener);}
This gateway can be configured to support apps and api using aTOML file as follows. There exists a sample file calledConfig.toml inside thexyz-gateway directory. SeeConfigure Ballerina Programs for more details.
# 1) API with no configured plugins[[ballerinax.gateway.apps]]basePath ="/api/xyz-service"endpointUrl ="https://run.mocky.io/v3/84643c67-6ddb-4cf1-8141-f637154c9520"# 2) Application with request plugins[[ballerinax.gateway.apps]]basePath ="/app/xyz-resource-cache"endpointUrl ="https://run.mocky.io/v3/34a9aeba-0b71-4fac-8451-b122c50cce45"[[ballerinax.gateway.apps.requestPlugins]]id ="AddAccessTokenPlugin"# 3) API with request and response plugins[[ballerinax.gateway.apps]]basePath ="/api/xyz-entitlement-service"endpointUrl ="https://run.mocky.io/v3/6613f69c-65cf-44d4-b29c-7887f21cfd59"[[ballerinax.gateway.apps.requestPlugins]]id ="NetworkControlPlugin"[[ballerinax.gateway.apps.responsePlugins]]id ="RemoveHeadersPlugin"# 4) Application with plugins having configs[[ballerinax.gateway.apps]]basePath ="/app/xyz-foo-bar"endpointUrl ="https://run.mocky.io/v3/34a9aeba-0b71-4fac-8451-b122c50cce45"[[ballerinax.gateway.apps.requestPlugins]]id ="NetworkControlPlugin"config = {level ="2"}# 5) Global request and response plugins[[ballerinax.gateway.requestPlugins]]id ="AddHeadersPlugin"config = {appId ="xyz-app"}[[ballerinax.gateway.responsePlugins]]id ="RemoveHeadersPlugin"config = {appId ="xyz-app"}
The pluginHazelcastMapClientPlugin is written to communicate with an existing Hazelcast cluster. This sample plugin is written to demonstrate the Java interoperability feature in Ballerina.
bal bindgen --public -mvn com.hazelcast:hazelcast:5.2.3 --output modules/hazelcast com.hazelcast.client.HazelcastClient com.hazelcast.core.HazelcastInstance com.hazelcast.map.IMap java.util.Set
- Refactor the codebase with custom Ballerina error types.
- Improve error handling and logic througout the codebase.
- Get rid of concurrency related warnings
About
Sample gateway written in Ballerina
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- Ballerina100.0%