The Alfresco Mock Event Generator is a Spring Boot application that generates random events and sends them to the Message Broker.
The generated events are selected from one of the following events categories:
- ACS_RAW_EVENT
- ACS_PUBLIC_EVENT
- ACTIVITI_RAW_EVENT
- ACTIVITI_PUBLIC_EVENT
- CLOUD_CONNECTOR_EVENT
The default events category is ACS_PUBLIC_EVENT. To override the default you can use System property:
-Dgenerator.eventCategory=<one-of-the-above-event-categories>
The default Message Broker is ActiveMQ, but RabbitMQ and Kafka are also supported and can be activated by the use of Spring Profile.
See application.yml for the available properties and their default values.
Note: Before running the application make sure that you have started a supported Message Broker.
For ActiveMQ and RabbitMQ the default host and port, that the application listens to are: localhost:5672
You will need to update the relevant properties if your broker is not using the default host and port.
To start the application with ActiveMQ:
mvn spring-boot:run
To start the application with ActiveMQ and different port. E.g. 5682:
mvn spring-boot:run -Dmessaging.to.activemq.port=5682
To start the application with ActiveMQ and ACS_RAW_EVENT category:
mvn spring-boot:run -Dgenerator.eventCategory=ACS_RAW_EVENT
To start the application with RabbitMQ:
mvn spring-boot:run -Dspring.profiles.active=rabbitMQ
To start the application with RabbitMQ and different port. E.g. 5682:
mvn spring-boot:run -Dspring.profiles.active=rabbitMQ -Dmessaging.to.rabbitmq.port=5682
To start the application with RabbitMQ and ACTIVITI_RAW_EVENT category:
mvn spring-boot:run -Dspring.profiles.active=rabbitMQ -Dgenerator.eventCategory=ACTIVITI_RAW_EVENT
To start the application with Kafka:
mvn spring-boot:run -Dspring.profiles.active=kafka
Executing any of the above commands will start the application, connect to the given broker and send 10 messages with a pause time of 1 second between each message. The messages are sent to the defined topic. See camelRoutes.destinationName in the application.yml file.
If you want to send events upon request rather than at the bootstrap time, then set the startSendAtStartup
property to false:
mvn spring-boot:run -Dgenerator.startSendAtStartup=false
then do an HTTP POST to the following URL:
http://<host>:<port>/alfresco/mock/events
Request payload example:
{
"schema": "org.alfresco.event.model.EventV1",
"type": "NODEADDED",
"streamPosition": "1532902795992-gg6vva",
"principal": "user1",
"resource": {
"schema": "org.alfresco.event.model.acs.NodeResourceV1",
"id": "489ced52-9b4c-4d71-8c67-99b1d340c0e6",
"primaryHierarchy": [
{
"id": "ea74ec76-3b7d-4c0e-8d2c-2cd212e255a9",
"type": "Node"
},
{
"id": "5ba21380-b302-4a86-984f-47eac9d5f058",
"type": "Node"
},
{
"id": "c2346c1d-4859-490b-9cd2-49a8d54d11ed",
"type": "Node"
},
{
"id": "c23ed6ab-b8de-4daa-ad1d-b1c0aed3d651",
"type": "Node"
},
{
"id": "f743f8b7-677e-4613-84e9-cfc7e9399eca",
"type": "Node"
}
],
"nodeType": "cm:content"
}
}
You can also optionally specify the topic name as the query parameter for the /events endpoint. For, example:
http://<host>:<port>/alfresco/mock/events?destinationName=helloWorld
for random events (based on the configured event category), do an HTTP POST to the following URL:
http://<host>:<port>/alfresco/mock/random-events
Note: You must specify at least a numOfEvents in your request payload.
Request payload example:
{
"numOfEvents" : 3,
"pauseTimeInMillis" : 50
}
The Cloud Connector event is a special case where you can override the inBoundVariables
and/or outBoundVariables
attributes.
The default Cloud Connector event looks like:
{
"appName": "default-app",
"appVersion": "",
"serviceName": "rb-my-app",
"serviceFullName": "rb-my-app",
"serviceType": "runtime-bundle",
"serviceVersion": "",
"integrationContext": {
"id": "1c7b99de-fa50-11e8-9b6d-8efb5254abd4",
"outBoundVariables": {},
"processInstanceId": "1c7b72c8-fa50-11e8-9b6d-8efb5254abd4",
"processDefinitionId": "ConnectorProcess:1:41f6f25f-fa0a-11e8-9b6d-8efb5254abd4",
"activityElementId": "sid-CDFE7219-4627-43E9-8CA8-866CC38EBA94",
"connectorType": "Example Connector",
"inBoundVariables": {
"firstName": "Paulo",
"lastName": "Silva",
"age": 25
}
}
}
To override the default event, first run the application with the following settings:
mvn spring-boot:run -Dspring.profiles.active=rabbitMQ -Dgenerator.startSendAtStartup=false -Dgenerator.eventCategory=CLOUD_CONNECTOR_EVENT
then do an HTTP POST to the following URL:
http://<host>:<port>/alfresco/mock/connector-event?destinationName=<topic-name>
Note: destinationName
parameter is optional. If you specify it, the event will be sent to that topic. If you don't specify it, the event will be sent to each topic from the application.yml
file.
In order to add a new topic, you need to specify a new entry under the camelRoutes
parent. E.g:
camelRoutes:
- destinationName: <your-topic-name>
toRoute: rabbitmq:${messaging.to.rabbitmq.camelRoutes[0].destinationName}?connectionFactory=#rabbitmqConnectionFactory&exchangeType=topic&autoDelete=false
Request payload example:
{
"inBoundVariables": {
"nodeId": "bd285b4f-9ee4-11e8-9079-0242ac118745",
"properties": {
"cm:title": "Node Title",
"cm:description": "Node Description"
}
}
}
Note: inBoundVariables
and outBoundVariables
are of type Map<String, Object>
so you can add whatever you require within the JSON body.
The scheduled option allows you to send n number of messages per s seconds for the duration of t seconds.
To start the application with the scheduler:
mvn spring-boot:run -Dgenerator.scheduled.enabled=true
The above command will start the application, connect to ActiveMQ and try to send 1000 messages per second for the duration of 10 seconds.
Note: Depending on your hardware, you may not be able to achieve such a number per second. Try disabling ActiveMQ persistence and increasing the JVM memory of the broker for the desired number.
For example, using ActiveMQ docker image:
docker run --name='activemq' -it --rm -e 'ACTIVEMQ_CONFIG_MINMEMORY=1024' -e 'ACTIVEMQ_CONFIG_MAXMEMORY=2048' -p 8161:8161 -p 5672:5672 -P webcenter/activemq:latest
If you want to compile the source code and build the Docker image, you need to run the following at the root of the project:
mvn clean package docker:build
This will build the Docker image locally.