Skip to content
Closed
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
51 changes: 49 additions & 2 deletions en/docs/develop/integration-artifacts/event/kafka.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,54 @@ title: Kafka
description: Consume messages from Apache Kafka topics with consumer group management and offset control.
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Kafka

Consume messages from Apache Kafka topics with consumer group management, offset control, and schema-aware deserialization.

## Creating a Kafka consumer

<Tabs>
<TabItem value="ui" label="Visual Designer" default>

1. Click the **+** **Add Artifacts** button in the canvas or click **+** next to **Entry Points** in the sidebar.
2. In the **Artifacts** panel, select **Kafka** under **Event Integration**.

![Artifacts panel showing Kafka under Event Integration](/img/develop/integration-artifacts/event/kafka/step-2.png)

3. In the creation form, fill in the following fields:

![Kafka consumer creation form](/img/develop/integration-artifacts/event/kafka/step-creation-form.png)

**Service Configurations**


| Field | Description |
|---|---|
| **Bootstrap Servers** | Comma-separated list of Kafka broker addresses (e.g., `localhost:9092`). Required. |
| **Topic(s)** | One or more Kafka topic names to subscribe to. Required. |

**Advanced Configurations**

Expand **Advanced Configurations** to set additional options including the consumer group ID, offset reset policy, and polling interval.

4. Click **Create**.

5. WSO2 Integrator opens the **Kafka Consumer Designer**. The header shows the listener configuration pill and the list of event handlers.

![Kafka Consumer Designer showing the listener configuration](/img/develop/integration-artifacts/event/kafka/step-3.png)

6. Click the `onConsumerRecord` handler row to open it in the **flow designer**.

![Flow designer showing the onConsumerRecord handler canvas](/img/develop/integration-artifacts/event/kafka/step-4.png)

7. Use the flow canvas to add integration steps — database writes, HTTP calls, and transformations.

</TabItem>
<TabItem value="code" label="Ballerina Code">

```ballerina
import ballerinax/kafka;

Expand Down Expand Up @@ -45,6 +89,9 @@ service on orderListener {
}
```

</TabItem>
</Tabs>

## Offset Management Strategies

| Strategy | Configuration | Behavior |
Expand All @@ -54,7 +101,7 @@ service on orderListener {
| **Seek to beginning** | `autoOffsetReset: "earliest"` | Reprocess from the beginning of the topic |
| **Seek to end** | `autoOffsetReset: "latest"` | Skip to the latest messages only |

## Common Patterns
<!-- ## Common Patterns

### Dead Letter Queue (DLQ)

Expand All @@ -71,7 +118,7 @@ function processWithDLQ(kafka:Caller caller, OrderEvent order) returns error? {
check caller->commit(); // Acknowledge so it does not reprocess
}
}
```
``` -->

### Acknowledgment Strategies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,46 @@ title: GraphQL Service
description: Build GraphQL APIs with queries, mutations, and subscriptions. (Beta)
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# GraphQL Service

Build GraphQL APIs with queries, mutations, and subscriptions.
GraphQL services let you build flexible APIs where clients request exactly the data they need. WSO2 Integrator automatically generates the GraphQL schema from your Ballerina types and supports queries, mutations, and real-time subscriptions.

:::note Beta
GraphQL service support is currently in beta.
:::

## Creating a GraphQL service

<Tabs>
<TabItem value="ui" label="Visual Designer" default>

1. Open the **WSO2 Integrator** sidebar in VS Code.
2. Click **+** next to **Services**.
3. Select **GraphQL Service** from the artifact type list.
4. In the creation form, fill in:
- **Name** — a name for the service.
- **Port** — the listener port (default: `9090`).
- **Base Path** — the GraphQL endpoint path (e.g., `/graphql`).
5. Click **Create**.

<!-- TODO: add screenshot — GraphQL service creation form -->

6. WSO2 Integrator opens the service in the **flow designer**. The canvas displays separate nodes for queries, mutations, and subscriptions.
7. Click **+ Add Query** to add a query resource, **+ Add Mutation** for mutations, or **+ Add Subscription** for subscriptions.
8. For each operation, define the return type and any input arguments.
9. Use the action palette to add data-fetching logic inside each operation.

<!-- TODO: add screenshot — Flow designer showing GraphQL service with query and mutation nodes -->

10. WSO2 Integrator generates the schema automatically from the Ballerina type definitions. Click **View Schema** to preview the generated SDL.

<!-- TODO: add screenshot — Generated GraphQL schema view -->

</TabItem>
<TabItem value="code" label="Ballerina Code">

```ballerina
import ballerina/graphql;
Expand Down Expand Up @@ -34,4 +71,59 @@ service /graphql on new graphql:Listener(9090) {
}
```

GraphQL services automatically generate the schema from Ballerina types. Use the built-in GraphQL Playground for interactive testing.
</TabItem>
</Tabs>

## GraphQL operation types

| Operation | Keyword | Description |
|---|---|---|
| **Query** | `resource function get` | Read data — analogous to HTTP GET |
| **Mutation** | `remote function` | Write data — analogous to HTTP POST/PUT/DELETE |
| **Subscription** | `resource function subscribe` | Real-time updates via WebSocket |

## Schema generation

Ballerina generates the GraphQL schema from your record types and function signatures automatically. No separate SDL file is needed.

```ballerina
type Product record {|
string id;
string name;
decimal price;
string category;
|};

type ProductInput record {|
string name;
decimal price;
string category;
|};
```

The above types map to the following GraphQL schema:

```graphql
type Product {
id: String!
name: String!
price: Decimal!
category: String!
}

input ProductInput {
name: String!
price: Decimal!
category: String!
}
```

## GraphQL Playground

Use the built-in GraphQL Playground for interactive testing. Navigate to `http://localhost:9090/graphql` in your browser after starting the service.

## What's next

- [HTTP Service](http-service.md) — expose integration logic over REST
- [Types](../supporting/types.md) — define shared record types for schema generation
- [Connections](../supporting/connections.md) — configure data source connections
66 changes: 65 additions & 1 deletion en/docs/develop/integration-artifacts/service/grpc-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,42 @@ title: gRPC Service
description: Define services using Protocol Buffers and generate Ballerina code for gRPC.
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# gRPC Service

Define services using Protocol Buffers and generate Ballerina code.
gRPC services use Protocol Buffers (protobuf) to define strongly-typed contracts and support four communication patterns: unary, server streaming, client streaming, and bidirectional streaming. WSO2 Integrator generates Ballerina service stubs from your `.proto` files.

## Creating a gRPC service

<Tabs>
<TabItem value="ui" label="Visual Designer" default>

1. Open the **WSO2 Integrator** sidebar in VS Code.
2. Click **+** next to **Services**.
3. Select **gRPC Service** from the artifact type list.
4. In the creation form, fill in:
- **Name** — a name for the service.
- **Port** — the gRPC listener port (default: `9090`).
- **Proto File** — optionally upload an existing `.proto` file, or start with a blank service.
5. Click **Create**.

<!-- TODO: add screenshot — gRPC service creation form with proto file upload option -->

6. WSO2 Integrator opens the service in the **flow designer**. Each RPC method from the proto definition appears as a separate resource node.
7. Click a resource node to open its implementation canvas.
8. Add integration steps using the action palette — database lookups, HTTP calls, and transformations.
9. To add a new RPC method, click **+ Add RPC** in the service node and choose the communication pattern (unary, server streaming, client streaming, or bidirectional).

<!-- TODO: add screenshot — Flow designer showing gRPC service with RPC method nodes -->

10. Switch to **Code View** to inspect the generated Ballerina service stub and edit the descriptor annotation if needed.

<!-- TODO: add screenshot — Code view of the generated gRPC service -->

</TabItem>
<TabItem value="code" label="Ballerina Code">

```ballerina
import ballerina/grpc;
Expand Down Expand Up @@ -35,3 +68,34 @@ service "OrderService" on new grpc:Listener(9090) {
}
}
```

</TabItem>
</Tabs>

## RPC communication patterns

| Pattern | Description | Use case |
|---|---|---|
| **Unary** | Single request, single response | Standard CRUD operations |
| **Server streaming** | Single request, stream of responses | Large result sets, real-time feeds |
| **Client streaming** | Stream of requests, single response | Bulk uploads, batch inserts |
| **Bidirectional streaming** | Stream of requests and responses | Chat, real-time collaboration |

## Generating code from proto files

WSO2 Integrator uses `bal grpc` to generate service stubs from protobuf definitions.

```bash
# Generate Ballerina service stub from a .proto file
bal grpc --input order_service.proto --output gen/ --mode service
```

This generates:
- `OrderService.bal` — service interface with all RPC methods
- `order_service_pb.bal` — message types and the descriptor constant

## What's next

- [HTTP Service](http-service.md) — expose integration logic over REST
- [Connections](../supporting/connections.md) — configure gRPC client connections
- [Types](../supporting/types.md) — define shared message types
Loading