Skip to content
Back to skills

Business Events

ASecurity

Define event-driven APIs over Kafka with Mendix business event services — publish and subscribe contracts, CREATE/DROP/DESCRIBE. Use when building publish/subscribe integration between apps, or inspecting the business event services a project already has.

  • 143 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 26, 2026
ai-agentsjavabashsqlapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned November 22, 2026

npx -y skills add mendixlabs/mxcli --skill business-events --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Business Events?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Business Events
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mendixlabs-business-events/badge)](https://www.skillsdirectory.com/skills/mendixlabs-business-events)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: business-events
description: "Define event-driven APIs over Kafka with Mendix business event services — publish and subscribe contracts, CREATE/DROP/DESCRIBE. Use when building publish/subscribe integration between apps, or inspecting the business event services a project already has."
---
<!-- skill-index: generated by scripts/skill-index.py; make check-skill-index -->
## Find it fast

`sed -n '<from>,<to>p' SKILL.md` one section rather than reading the file;
`./mxcli syntax <topic>` answers *how do I write this* for a fraction of either.

| lines | section |
|---|---|
| 24-31 | When to Use This Skill |
| 32-168 | Commands |
| 169-200 | Message Definition Syntax |
| 201-208 | Service Properties |
| 209-216 | Operations |
| 217-263 | Publishing Events from Microflows |
| 264-276 | Checklist |

<!-- /skill-index -->
# Business Events

## When to Use This Skill

Use this skill when the user wants to:
- Define event-driven APIs using Kafka/message brokers
- Create business event services that publish events
- View or describe existing business event services
- Set up publish/subscribe message channels

## Commands

### View Business Events

```sql
-- List all business event service documents
list business event services;

-- Filter by module
list business event services in MyModule;

-- List all business event client documents (future)
list business event clients;

-- List individual messages across all services
list business events;

-- Filter messages by module
list business events in MyModule;

-- Full MDL description (round-trippable for a PUBLISHED service)
describe business event service Module.ServiceName;
```

`list business event services` has a **Kind** column: `published` (a definition of its
own) or `consumed` (no definition, the producer's AsyncAPI contract cached instead). A
consumed service shows 0 messages because its messages live in the contract, not in a
definition — the kind is what makes that legible. `list business events` lists both
roles' events with the **Channel** the broker derives the topic from.

### Author a Consumed Service

A **consumed** service stores the producing app's AsyncAPI contract instead of a
definition of its own, and binds events from it:

```sql
mdl 1;
create or modify business event service Module.OrdersEventClient
(
  ContractFile: 'contracts/OrdersEventService.yaml'   -- or Contract: $$<yaml>$$
)
{
  consume OrderPlaceEvent (Entity: Module.CBE_OrderPlaceEvent, Microflow: Module.HandleBE_OrderPlaceEvent);
};
```

- Exactly one of `Contract:` / `ContractFile:`, and neither may be mixed with
  `ServiceName`, `EventNamePrefix` or `message` — those are the published shape.
- `ContractFile` is read when the script runs and stored **verbatim**, so nothing later
  depends on the file. `describe` prints the `Contract:` form, which re-executes anywhere.
- It is `consume`, not `subscribe`: `message X (…) subscribe` already means "this app
  consumes X of its *own* definition". The stored `Operation` is `"subscribe"` either
  way; only the keyword differs.
- The consumed entity (`CBE_…`, extending `BusinessEvents.ConsumedBusinessEvent`) and the
  handler microflow are ordinary MDL, declared before the service.
- A service whose contract contains `$$` cannot be described inline — `$$…$$` has no
  escape — so `describe` falls back to comments and tells you to use `ContractFile`.

A published-shaped statement over a stored contract is still refused rather than allowed
to destroy it (ako/mxcli#2381).

### Two Apps: Export the Contract, Then Consume It

The producing app mints the channel id and it reaches the consumer **inside the exported
contract** — not by both apps spelling the same string. `export contract` writes the
document Studio Pro's *Export AsyncAPI Document* button produces:

```bash
mxcli export contract CdcPublish.OrdersEventService -p appA.mpr -o contract.yaml
```

Then name that file in app B's script (`ContractFile: 'contract.yaml'`). Both apps then
show the same Channel in `list business events`, which is what the broker derives the
topic from.

Only business event services export so far. A published OData or REST service's contract
is served by the running app, so exporting one means fetching rather than rendering it.

Payload types: only `Long` is measured against a Studio Pro export, so the renderer
refuses the others rather than guess (#2384 §9.1) — export from Studio Pro and use
`ContractFile:` for a service that uses them.

### Create a Business Event Service

```sql
mdl 1;
create business event service Module.CustomerEventsApi
(
  ServiceName: 'CustomerEventsApi',
  EventNamePrefix: 'com.example'
)
{
  message CustomerChangedEvent (CustomerId: long) {
    publish (Entity: Module.PBE_CustomerChangedEvent);
  };
  message AddressChangedEvent (AddressId: long) {
    publish (Entity: Module.PBE_AddressChangedEvent);
  };
};
```

### Create or Modify (Idempotent Update — Preferred)

Preserves the existing UUID so other documents that reference this service remain valid.
`OR REPLACE` is accepted as a synonym. Each message keeps its stored channel — the
channel name is what the broker derives the Kafka topic from
(`businessevents.<channel id>.<space>`) — matched by message name, so a re-run of an
unchanged script reports `Unchanged`; only a new message gets a new (random) channel
name. Renaming a message is a new channel.

There is no MDL property to state a channel name, and that is correct: the producing app
mints the id, and it reaches a consumer **inside the exported AsyncAPI contract**, not by
both apps spelling the same string. Read it with `list business events` (Channel column)
or `show contract channels from Module.Service`, which works on a publisher as well as a
consumer.

```sql
mdl 1;
create or modify business event service Module.CustomerEventsApi
(
  ServiceName: 'CustomerEventsApi',
  EventNamePrefix: ''
)
{
  message CustomerChangedEvent (CustomerId: long) {
    publish (Entity: Module.PBE_CustomerChangedEvent);
  };
};
```

### Drop a Business Event Service

```sql
mdl 1;
drop business event service Module.CustomerEventsApi;
```

## Message Definition Syntax

A message's operations are its children, each with its properties in `( )`:

```
message <MessageName> (<AttrName>: <type>, ...) {
  publish (Entity: <Module.PBE_Entity>);
  subscribe (Entity: <Module.CBE_Entity>, Microflow: <Module.Handler>);
};
```

Give a message the operations it has: `publish` only, `subscribe` only, or both, for
a message the app publishes and consumes itself (an in-app bus, a request/reply loop).

Declare a message **once**. The same name declared twice (once per operation) stores
two messages of one name, which `mx check` accepts and the deployment rejects ("An item
with the same key has already been added"); `check` refuses it.

The keyword clauses `message X (…) publish entity M.E microflow M.H;` and
`consume X entity M.E microflow M.H;` are the old spelling (MDL-DEPR075, MDL-DEPR076):
they still run, warn, and `mxcli fmt --upgrade` rewrites them.

### Supported Attribute Types
- `string`, `string(n)`, `string(unlimited)` - Text. The length must match the
  linked entity attribute's; a bare `string` stores no length, which the build
  reads as 200
- `integer` - 32-bit integer
- `long` - 64-bit integer
- `decimal` - Precise decimal number
- `boolean` - True/false
- `datetime` - Date and time

## Service Properties

| Property | Description |
|----------|-------------|
| `ServiceName` | The service name used in the event broker |
| `EventNamePrefix` | Prefix added to event names (can be empty) |
| `folder` | Optional folder path for the service document |

## Operations

| Operation | Description |
|-----------|-------------|
| `publish` | This service publishes the event (other apps subscribe) |
| `subscribe` | This service subscribes to the event (other apps publish) |
| both | One message the app publishes and consumes: a `publish` and a `subscribe` child |

## Publishing Events from Microflows

There is no dedicated microflow activity for publishing business events. Instead, Mendix
provides Java actions in the `BusinessEvents` marketplace module. Use `call java action`
to publish an event from a microflow:

```sql
-- Create an event entity instance and publish it
create microflow Module.ACT_PublishCustomerChanged
  folder 'ACT'
begin
  $event = create Module.PBE_CustomerChangedEvent (CustomerId = $CustomerId);
  commit $event;
  call java action BusinessEvents.PublishBusinessEvent_V2(
    Subject = 'Customer {1} changed' with ({1} = $CustomerId),
    BusinessEvent = $event
  );
end;
```

`PublishBusinessEvent_V2` takes two parameters: `Subject`, a **text template**
(`StringTemplate(Text)`), and `BusinessEvent`, the event object. `Subject` is
written like a log message — a string, or `'… {1} …' with ({1} = …)`; each
argument must be a String, Integer, Decimal, Boolean or DateTime value (wrap an
enumeration in `getCaption(…)`). `describe java action` shows the parameters of
any action before you call it.

### Available Java Actions (from BusinessEvents module)

| Java Action | Description |
|-------------|-------------|
| `BusinessEvents.PublishBusinessEvent_V2` | Publish an event (recommended) |
| `BusinessEvents.PublishBusinessEvent` | Publish an event (legacy) |
| `BusinessEvents.ConsumeBusinessEvent` | Consume/acknowledge an event |
| `BusinessEvents.PublishEvents` | Publish multiple events |
| `BusinessEvents.StartupBusinessEvents` | Initialize the event broker connection |
| `BusinessEvents.ShutdownBusinessEvents` | Shut down the event broker connection |

### Typical Pattern

1. Define a Business Event Service with PUBLISH messages
2. Create entities prefixed with `PBE_` that **extend `BusinessEvents.PublishedBusinessEvent`**
3. Entity attributes must **exactly match** the message attributes (no extra attributes on the entity)
4. In microflows, create an instance of the event entity, populate its attributes, commit it
5. Call `BusinessEvents.PublishBusinessEvent_V2` with a `Subject` template and the entity instance as `BusinessEvent`
6. For subscribe operations, link a handler microflow in the service definition

## Checklist

- [ ] Linked entities must exist before creating the service
- [ ] **Entities must extend `BusinessEvents.PublishedBusinessEvent`** (for published events)
- [ ] **Entity attributes must exactly match the message attributes** (no extra/missing attributes)
- [ ] **No message attribute may reuse a name the entity inherits** from `BusinessEvents.PublishedBusinessEvent` (e.g. `EventId`) — an inherited attribute does not count, so mxbuild reports it "not present on the entity". `check -p … --references` reports it
- [ ] Entity names use qualified format: `Module.EntityName`
- [ ] Entities for published events are conventionally prefixed with `PBE_`
- [ ] Attribute types must be valid (String, Integer, Long, Decimal, Boolean, DateTime)
- [ ] Use `describe business event service` to verify the result
- [ ] The DESCRIBE output is parseable and can be used as a CREATE statement
- [ ] To publish events from microflows, use `call java action BusinessEvents.PublishBusinessEvent_V2`
- [ ] The `BusinessEvents` module must be included in the project (marketplace module)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.