|
| 1 | +--- |
| 2 | +title: "Business Events Configuration" |
| 3 | +url: /appstore/services/business-events-configuration/ |
| 4 | +description: "Describes the configuration and usage of the Mendix Business Events service." |
| 5 | +#If moving or renaming this doc file, implement a temporary redirect and let the respective team know they should update the URL in the product. See Mapping to Products for more details. |
| 6 | +--- |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +To work with business events, import the [Mendix Business Events](https://marketplace.mendix.com/link/component/202649) service into your app. See the [Installing Marketplace Content](/appstore/use-content/#install) section in *Using Marketplace Content* for more details. |
| 11 | + |
| 12 | +## Configuration |
| 13 | + |
| 14 | +### Configuring Local Deployments {#config-local-deployment} |
| 15 | + |
| 16 | +To test on your development workstation, run the Event Broker on your machine using [Docker](https://www.docker.com/). The required configuration can be found in the [local setup for the event broker tool](https://github.com/mendix/event-broker-tools). |
| 17 | + |
| 18 | +For local deployment, you need to set the **ChannelName** and **ServerUrl** constants. These constants are best configured by following these steps: |
| 19 | + |
| 20 | +1. Open the **App Settings**. |
| 21 | +2. On the **Configuration** tab, click **New**. |
| 22 | +3. Open the **Constants** tab and set the constants as follows: |
| 23 | + |
| 24 | + * **ChannelName**: `local` |
| 25 | + * **ServerUrl**: |
| 26 | + * On Windows: `localhost:9092` |
| 27 | + * Running Docker on MacOS and Studio Pro on Windows via Parallels: `10.211.55.2:9094` |
| 28 | + * Running Docker on Linux and Studio Pro on Windows via VirtualBox/KVM: `<IP ADDRESS>:9094` |
| 29 | + |
| 30 | +### Changing Logging Interval (Optional) |
| 31 | + |
| 32 | +Optionally, you can set **SummaryLogIntervalSeconds** to a different value. The default value 120, which means if events are consumed or produced, an overview of what was consumed or produced will be logged at `INFO` level every 120 seconds. When configured with 0 or a negative number, this additional logging will not take place at all. |
| 33 | + |
| 34 | +## Using Business Events {#two-way-be} |
| 35 | + |
| 36 | +Studio Pro 9.24 and above supports newer behavior of business events, sometimes called two-way business events. In these versions, business events are published by an app and one or more apps consume, or subscribe to, the events. A publisher can also consume a business event of some other publishing app, and a subscriber can publish a business event to another app. |
| 37 | + |
| 38 | +### Creating a New Business Event Service {#two-way-be-create} |
| 39 | + |
| 40 | +In your defining app, you can create a new service by doing the following: |
| 41 | + |
| 42 | +1. Right-click the service folder, hover over **Add other**, then click **Business Event Service**. |
| 43 | +2. Select **Create a new business event service**. |
| 44 | +3. Enter a **Document name** for the [business event service document](/refguide/business-event-services/) |
| 45 | +4. Click **OK**. |
| 46 | + |
| 47 | +The business event service document is open in Studio Pro: |
| 48 | + |
| 49 | +{{< figure src="/attachments/appstore/platform-supported-content/services/business-events/business-events-config/new-business-event-service.png" class="no-border" >}} |
| 50 | + |
| 51 | +### Adding Event Definitions {#add-be-definitions} |
| 52 | + |
| 53 | +To define what information is included in your events and what the service will implement, click **Add** in the open service document: |
| 54 | + |
| 55 | +{{< figure src="/attachments/appstore/platform-supported-content/services/business-events/business-events-config/add-event-definition.png" class="no-border" >}} |
| 56 | + |
| 57 | +1. Define what information is included in this event. |
| 58 | + |
| 59 | + * In the **General** field, provide the **Event name** and **Description** to let others know what the service is about. |
| 60 | + * In the **Attributes** field, click **Add** to define attributes. |
| 61 | + * Changes you make here later could lead to breaking changes if the entity the attribute belongs to is consumed. Related entities will be updated automatically. |
| 62 | + |
| 63 | + {{< figure src="/attachments/appstore/platform-supported-content/services/business-events/business-events-config/wizard-step-1.png" class="no-border" width="400" >}} |
| 64 | + |
| 65 | +2. Decide what other apps can do and what service this will implement. |
| 66 | + |
| 67 | + * In the **Other apps can** field, you can select how other apps can use the service. The **This Business Events service implements** field defines whether the service will be responsible for publishing events, subscribing to events, or both. |
| 68 | + * Below is an explanation of the possibilities for what other apps can do and what the service implements: |
| 69 | + |
| 70 | + | If you say that other apps can: | Then the service itself must implement: | The service could also implement: | The following are automatically created: | |
| 71 | + | ---------- | ---------- | ---------- | ---------- | |
| 72 | + | Publish events | Subscribing to events | Publishing events | **ConsumedBusinessEvent** entity and a [handler microflow](#two-way-be-handler) | |
| 73 | + | Subscribe to events | Publishing events | Subscribing to events | When publishing, **PublishedBusinessEvent** entity and handler microflow <br>If subscribing, a **ConsumedBusinessEvent** entity | |
| 74 | + | Publish events and<br>Subscribe to events | [Nothing required: if apps can do both, there is no obligation for the service to implement anything] | Publishing events and/or subscribing to events | If no service implementations are selected, then nothing created <br>If publishing, **PublishedBusinessEvent** entity and handler microflow <br>If subscribing, a **ConsumedBusinessEvent** entity <br>If both, then both entities and the handler microflow are created| |
| 75 | + |
| 76 | +3. Click **Done** to exit the wizard and view the defined service document. |
| 77 | + |
| 78 | + * **Export AsyncAPI Document** exports the YAML file of the business event service so other apps can [use your newly created service](#two-way-be-existing). |
| 79 | + |
| 80 | +### Attribute Types {#attribute-types} |
| 81 | + |
| 82 | +Attribute types for business events relate to attribute types of entities, but not all attribute types are supported for business events. The following attribute types are not supported: |
| 83 | + |
| 84 | +* AutoNumber |
| 85 | +* Binary |
| 86 | +* Hashed string |
| 87 | +* Enumeration (see [Enumeration Attribute Type](#enum-att-type) below) |
| 88 | + |
| 89 | +In Studio Pro 9.24 and below, all types were supported implicitly because a business event was defined by an entity. The unsupported types were from the perspective of the consumer received as a string. |
| 90 | + |
| 91 | +#### Enumeration Attribute Type {#enum-att-type} |
| 92 | + |
| 93 | +In Studio Pro [9.24](/releasenotes/studio-pro/9.24/), consumers see enumerations as a plain string. The names of the enumeration items are the values that are transmitted by the event broker to the subscribers. Enumerations cannot be modeled for new services in Studio Pro [9.24](/releasenotes/studio-pro/9.24/), but for converted earlier apps, the functionality is maintained. |
| 94 | + |
| 95 | +In Studio Pro [10.0](/releasenotes/studio-pro/10.0/) and above, enumerations are fully supported. The enumeration attribute type can be modeled. The enumeration items are stored in the exported AsyncAPI document, and when imported, a new enumeration document will be created with the name *<attributeName>Enum*. The **Caption** and **Image** fields are not transmitted to the importer of the AsyncAPI document. Captions and images can be provided manually and will not cause conflicts when an AsyncAPI document is re-imported. |
| 96 | + |
| 97 | +### Using an Existing Business Event Service {#two-way-be-existing} |
| 98 | + |
| 99 | +To use an existing business service in Studio Pro 9.24 and above, do the following: |
| 100 | + |
| 101 | +1. Right-click the service folder, hover over **Add other**, then click **Business Event Service**. |
| 102 | +2. Select **Use an existing business event service**. |
| 103 | +3. Click **Browse** and navigate to the YAML file you exported from the publishing app. |
| 104 | +4. Enter a **Document name**, or use the default name, for the [business event service document](/refguide/business-event-services/). |
| 105 | +5. Click **OK**. |
| 106 | + |
| 107 | +### Publishing and Subscribing to Business Events |
| 108 | + |
| 109 | +After following the instructions in [Using an Existing Business Event Service](#two-way-be-existing), you can publish or subscribe (or both, depending on the [service definitions](#add-be-definitions)) in the following ways: |
| 110 | + |
| 111 | +* Open the business service document and click **Add** |
| 112 | +* Drag and drop the business event from the [Integration pane](/refguide/integration-pane/) to your domain model |
| 113 | + |
| 114 | +To publish a business event service, you need to use it in a microflow. |
| 115 | + |
| 116 | +## Automatically Created Event Handler Microflow and Entity {#two-way-be-handler} |
| 117 | + |
| 118 | +When you click **Add** to add the events from the document into your service, Studio Pro will automatically create a persistable consumed entity within your domain model and an [Event Handler](/refguide/event-handlers/) microflow (**Handle_BE**) to manage the flow of the event after delivery. The **Event Handler** microflow is created in the same directory as your service. |
| 119 | + |
| 120 | +Currently, Mendix does not support multiple subscribers to the same business event within the same app. |
| 121 | + |
| 122 | +## Read More |
| 123 | + |
| 124 | +* [Deploy a Business Event](/appstore/services/business-events-deployment/) |
| 125 | +* [Mendix Event Broker](/appstore/services/event-broker/) |
0 commit comments