Skip to main content
Version: Current

API reference - network API

Use these APIs to send and receive messages between micro-services.

ClientConnectionsManager

Use @Inject to create ClientConnectionsManager.

See the example below:

class TestService(@Inject val clientConnectionManager: ClientConnectionsManager) {}

GenesisMessageClient

GenesisMessageClient is a messaging client that can be obtained using ClientConnectionManager. Here is an example:

If you connect successfully to the POSITION_APP_EVENT_HANDLER service, you will get GenesisMessageClient. Otherwise, you will get null.

class TestAuthManagerService(@Inject val clientConnectionManager: ClientConnectionsManager) {
private val genesisMessageClient = clientConnectionManager.getGenesisMessageClient("POSITION_APP_EVENT_HANDLER")
// custom code here
}

Constructor

GenesisMessageClient(address: String, port: Int, secure: Boolean, configuration: NetworkConfiguration)

Functions

NameSignature
addConnectionEventHandlerfun addConnectionEventHandler(handler: ConnectionEventHandler)
removeConnectionEventHandlerfun removeConnectionEventHandler(handler: ConnectionEventHandler)
requestfun <I : Inbound, O : Outbound> request(messageWorkflow: DataWorkflow<I, O>, timeout: Int = configuration.reqRepTimeout,): Single<O>
requestsuspend fun <I : Any, O : Any> request(messageWorkflow: RequestReplyDataWorkflow<I, O>,timeout: Int = configuration.reqRepTimeout,): Reply<O>
requestfun <I : Inbound, O : Outbound> request(message: I, output: Class<O>, timeout: Int = configuration.reqRepTimeout,): Single<O>
requestsuspend inline fun <reified O : Outbound> request(message: Inbound, messageType: String, timeout: Int = configuration.reqRepTimeout,): O
requestParametricsuspend inline fun <reified O, reified P : Any> requestParametric(message: Inbound, messageType: String, timeout: Int = configuration.reqRepTimeout,):
sendMessagefun sendMessage(set: GenesisSet): Boolean
sendMessagefun sendMessage(set: GenesisMessage): Boolean
sendMessagesfun sendMessages(sets: List<GenesisSet>)
sendReqRepfun sendReqRep(set: GenesisSet, consumer: Consumer<GenesisSet>)
sendReqRepfun sendReqRep(set: GenesisSet, consumer: Consumer<GenesisSet>, reqRepTimeout: Int,)
sendReqRepfun sendReqRep(set: GenesisSet): ListenableFuture<GenesisSet>
sendReqRepfun sendReqRep(set: GenesisSet, reqRepTimeout: Int,): ListenableFuture<GenesisSet>
shutdown@Throws(InterruptedException::class) fun shutdown()
suspendRequestsuspend inline fun <reified I : Inbound, reified O : Outbound> suspendRequest(message: I, timeout: Int = configuration.reqRepTimeout,): O?
suspendRequestsuspend inline fun <reified I : Inbound, reified O : Outbound> suspendRequest(messageWorkflow: DataWorkflow<I, O>, timeout: Int = configuration.reqRepTimeout,): O?

Properties

NameSummary
handlerGives GenesisMessageHandler, which allows us to attach listeners to servers and clients
isActiveChecks whether netty connector is open for new connection
isConnectedChecks whether netty connector is open for new connection

Example:

class TestAuthManagerService(@Inject val clientConnectionManager: ClientConnectionsManager) {  
private val genesisMessageClient = clientConnectionManager.getGenesisMessageClient("GENESIS_AUTH_MANAGER")
fun sendMessageToEventHandler() {
genesisMessageClient?.waitForConnection()
genesisMessageClient?.sendReqRep(
genesisSet {
MESSAGE_TYPE with "EVENT_LOGIN_AUTH"
SERVICE_NAME with "GENESIS_AUTH_MANAGER"
SOURCE_REF with "sourceRef"
DETAILS with genesisSet {
USER_NAME with "User"
PASSWORD with "Password"
}
}
)?.get()
genesisMessageClient?.shutdown()
}
}

GenesisMessageHandler

GenesisMessageHandler enables you to attach listeners to servers and clients.

Functions

NameSignature
addListenerfun addListener(listener: GenesisMessageListener<V>)
removeListenerfun removeListener(listener: GenesisMessageListener<V>)

GenesisMessageListener

GenesisMessageListener is a functional interface with method onNewMessage, which listens for any new messages. @FunctionalInterface public interface GenesisMessageListener<V extends GenesisMessage>

onNewMessage

This method is called when a new message is received.

Example:

class CreateListener(@Inject val clientConnectionManager: ClientConnectionsManager) {    
private val genesisMessageClient = clientConnectionManager.getGenesisMessageClient("GENESIS_AUTH_MANAGER")
fun listener(args: Array<String>) {
// Add listener which prints GenesisSet
genesisMessageClient?.handler?.addListener {
set: GenesisSet?, channel: GenesisChannel? -> println(set)
}
// Listener gets called when new message is received
genesisMessageClient?.sendMessage(genesisSet {
MESSAGE_TYPE with "EVENT_LOGIN_AUTH"
SERVICE_NAME with "GENESIS_AUTH_MANAGER"
SOURCE_REF with "sourceRef"
DETAILS with genesisSet {
USER_NAME with "User"
PASSWORD with "Password"
}
})
}
}