business-events
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 inspec
SKILL.md.claude/skills/mendix/business-events/SKILL.md
GitHub<!-- skill-index: generated by scripts/skill-index.py; make check-skill-index -->
<!-- /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-101 | Commands |
| 102-117 | Message Definition Syntax |
| 118-125 | Service Properties |
| 126-132 | Operations |
| 133-169 | Publishing Events from Microflows |
| 170-182 | Checklist |
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
-- 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)
describe business event service Module.ServiceName;
Create a Business Event Service
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 the Kafka topic subscribers listen on — 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, so two apps defining "the same" service get different topics.
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
mdl 1;
drop business event service Module.CustomerEventsApi;
Message Definition Syntax
message <MessageName> (<AttrName>: <type>, ...) publish|subscribe
[entity <Module.EntityName>]
[microflow <Module.MicroflowName>];
Supported Attribute Types
string- Textinteger- 32-bit integerlong- 64-bit integerdecimal- Precise decimal numberboolean- True/falsedatetime- 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) |
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:
-- 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(EventObject = $event);
end;
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
- Define a Business Event Service with PUBLISH messages
- Create entities prefixed with
PBE_that extendBusinessEvents.PublishedBusinessEvent - Entity attributes must exactly match the message attributes (no extra attributes on the entity)
- In microflows, create an instance of the event entity, populate its attributes, commit it
- Call
BusinessEvents.PublishBusinessEvent_V2passing the entity instance - 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 … --referencesreports 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 serviceto 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
BusinessEventsmodule must be included in the project (marketplace module)