Skip to content

Instantly share code, notes, and snippets.

View wasin-waeosri's full-sized avatar
🎯
Focusing

Wasin Waeosri wasin-waeosri

🎯
Focusing
View GitHub Profile
@wasin-waeosri
wasin-waeosri / Dockerfile
Created August 24, 2023 06:53
Dockerfile for Kotlin-EMA-RTO article
FROM maven:3.9.3-eclipse-temurin-11-alpine as builder
LABEL authors="Developer Relations"
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline -B
COPY src ./src
RUN mvn clean -e -B package
FROM openjdk:11-jre-slim-bullseye
#FROM openjdk:17.0.2-slim-bullseye
@wasin-waeosri
wasin-waeosri / KonsumerRTO.kt
Created August 24, 2023 06:51
AppClient class for Kotlin-EMA-RTO article
class AppClient : OmmConsumerClient {
private val _loginRefresh: LoginRefresh = EmaFactory.Domain.createLoginRefresh()
private val _loginStatus: LoginStatus = EmaFactory.Domain.createLoginStatus()
override fun onRefreshMsg(refreshMsg: RefreshMsg, event: OmmConsumerEvent) {
....
if (refreshMsg.domainType() == EmaRdm.MMT_LOGIN) {
_loginRefresh.clear()
println(_loginRefresh.message(refreshMsg).toString())
@wasin-waeosri
wasin-waeosri / KonsumerRTO.kt
Created August 24, 2023 06:50
AppClient class for Kotlin-EMA-RTO article
class AppClient : OmmConsumerClient {
private val _loginRefresh: LoginRefresh = EmaFactory.Domain.createLoginRefresh()
private val _loginStatus: LoginStatus = EmaFactory.Domain.createLoginStatus()
override fun onRefreshMsg(refreshMsg: RefreshMsg, event: OmmConsumerEvent) {
...
if (refreshMsg.dataType() == EmaRdm.MMT_LOGIN) {
_loginRefresh.clear()
println(_loginRefresh.message(refreshMsg).toString())
@wasin-waeosri
wasin-waeosri / KonsumerRTO.kt
Created August 24, 2023 06:49
AppClient class for Kotlin-EMA-RTO article
class AppClient : OmmConsumerClient {
override fun onRefreshMsg(refreshMsg: RefreshMsg, event: OmmConsumerEvent) {
println("Received Refresh. Item Handle: ${event.handle()} Closure: ${event.closure()}")
println("Item Name: ${if (refreshMsg.hasName()) refreshMsg.name() else "<not set>"}")
println("Service Name: ${if (refreshMsg.hasServiceName()) refreshMsg.serviceName() else "<not set>"}")
println("Item State: ${refreshMsg.state()}")
println(refreshMsg)
}
@wasin-waeosri
wasin-waeosri / KonsumerRTO.kt
Created August 24, 2023 06:48
Consumer class for Kotlin-EMA-RTO article
fun run(clientId: String, clientSecret: String, serviceName: String = "ELEKTRON_DD") {
...
private val itemName = "EUR="
try {
val appClient = AppClient()
val config: OmmConsumerConfig = EmaFactory.createOmmConsumerConfig()
...
// --------------------------------- View ---------------------------
@wasin-waeosri
wasin-waeosri / KonsumerRTO.kt
Created August 24, 2023 06:47
Consumer class for Kotlin-EMA-RTO article
fun run(clientId: String, clientSecret: String, serviceName: String = "ELEKTRON_DD") {
var consumer: OmmConsumer? = null
val oAuthCallback = OAuthcallback()
val credentials = CredentialStore(clientId, clientSecret, consumer)
try {
val appClient = AppClient()
val config: OmmConsumerConfig = EmaFactory.createOmmConsumerConfig()
@wasin-waeosri
wasin-waeosri / KonsumerRTO.kt
Created August 24, 2023 06:47
Consumer class for Kotlin-EMA-RTO article
fun run(clientId: String, clientSecret: String, serviceName: String = "ELEKTRON_DD") {
var consumer: OmmConsumer? = null
val oAuthCallback = OAuthcallback()
val credentials = CredentialStore(clientId, clientSecret, consumer)
try {
val appClient = AppClient()
val config: OmmConsumerConfig = EmaFactory.createOmmConsumerConfig()
@wasin-waeosri
wasin-waeosri / KonsumerRTO.kt
Created August 24, 2023 06:46
Consumer class for Kotlin-EMA-RTO article
/* This is for example purposes, For best security, please use a proper credential store. */
data class CredentialStore(var clientSecret: String, var clientId: String, var consumer: OmmConsumer?)
/* Implementation of OmmOAuth2ConsumerClient. This is a very basic callback that uses the closure to obtain
* the OmmConsumer and call submitOAuthCredentialRenewal.
*
* This is intended to show functionality, so this example does not implement or use secure credential storage.
*/
class OAuthcallback : OmmOAuth2ConsumerClient {
override fun onOAuth2CredentialRenewal(event: OmmConsumerEvent?) {
@wasin-waeosri
wasin-waeosri / EmaConfig.xml
Created August 24, 2023 06:44
EmaConfig.xml for Kotlin-EMA-RTO article
<Channel>
<Name value="Channel_4"/>
<ChannelType value="ChannelType::RSSL_ENCRYPTED"/>
<CompressionType value="CompressionType::None"/>
<GuaranteedOutputBuffers value="5000"/>
<!-- EMA discovers a host and a port from RDP service discovery for the specified location
when both of them are not set and the session management is enable. -->
<Location value="ap-southeast"/>
<EnableSessionManagement value="1"/>
<ObjectName value=""/>
@wasin-waeosri
wasin-waeosri / KonsumerRTO.kt
Created August 24, 2023 06:43
Consumer class for Kotlin-EMA-RTO article
class KonsumerRTO {
private val tokenUrlV2 = "https://api.refinitiv.com/auth/oauth2/v2/token"
private val itemName = "EUR="
fun run(clientId: String, clientSecret: String, serviceName: String = "ELEKTRON_DD") {
var consumer: OmmConsumer? = null
try {