Spring
eventmesh-connector-spring is a Spring Boot starter, not a standalone main() connector. Add the module to a Spring Boot application. EventMeshAutoConfiguration registers the source, sink, and connect-server beans.
The source takes objects from your application (SpringSourceConnector.send) and publishes them to EventMesh. The sink takes events from EventMesh and delivers them to methods annotated with @EventMeshListener.
SpringSinkConnector: From EventMesh to Spring
- Start EventMesh Runtime.
- Enable the sink (
sinkEnable: trueinserver-config.yml) and checksink-config.yml. - Start the Spring Boot application that depends on
eventmesh-connector-spring.EventMeshListenerBeanPostProcessorstartsSpringSinkConnectorand invokes each@EventMeshListenermethod with records from the sink queue. - Send a message to EventMesh on
pubSubConfig.subject; the listener method receives it.
@Component
public class SpringSubHandler {
@EventMeshListener
public void onMessage(String message) {
// handle payload
}
}
pubSubConfig:
meshAddress: 127.0.0.1:10000
subject: TEST-TOPIC-SPRING
idc: FT
env: PRD
group: springSink
appId: 5033
userName: springSinkUser
passWord: springPassWord
sinkConnectorConfig:
connectorName: springSink
SpringSourceConnector: From Spring to EventMesh
- Start EventMesh Runtime.
- Enable the source (
sourceEnable: trueinserver-config.yml) and checksource-config.yml. - Start the Spring Boot application.
SpringConnectServer(aCommandLineRunner) startsSpringSourceConnector. Inject that bean and callsend. - The payload is published to
pubSubConfig.subjectin EventMesh Runtime.
@RestController
public class SpringPubController {
@Autowired
private SpringSourceConnector springSourceConnector;
@RequestMapping("/spring/pub")
public String publish() {
springSourceConnector.send("{\"content\":\"testSpringPublishMessage\"}");
return "success!";
}
}
pubSubConfig:
meshAddress: 127.0.0.1:10000
subject: TEST-TOPIC-SPRING
idc: FT
env: PRD
group: springSource
appId: 5033
userName: springSourceUser
passWord: springPassWord
sourceConnectorConfig:
connectorName: springSource
Configuration
pubSubConfig is the EventMesh TCP client used to publish into or subscribe from Runtime.
sourceConnectorConfig / sinkConnectorConfig fields:
connectorName: name of the connector.
server-config.yml:
sourceEnable: startSpringSourceConnectorfromSpringConnectServer.sinkEnable: startSpringSinkConnectorfromEventMeshListenerBeanPostProcessor.
@EventMeshListener.requestTimeout is the queue poll timeout in seconds (default 5).
Spring environment properties whose keys start with eventmesh.connector. are copied onto source records as extensions (prefix stripped, key lowercased).
Precautions
- This module cannot run on its own. Depend on it from a Spring Boot application (
META-INF/spring.factoriesauto-configuration). - Bundled
server-config.ymlsetssourceEnable: trueandsinkEnable: true. Turn off the side you are not running. - Bundled
source-config.yml/sink-config.ymluse aconnectorConfigkey. Jackson bindssourceConnectorConfigandsinkConnectorConfigon the Java config classes; use those field names. SpringConnectServerstarts only the source worker. The sink worker is started byEventMeshListenerBeanPostProcessor, not bySpringConnectServer.@EventMeshListenermethods must take exactly one argument.Stringreceives the payload bytes as text; any other type is JSON-deserialized.- See
eventmesh-examples(SpringPubController/SpringSubHandler) for a full sample.