Anyone know how I can expose members to routes / a...
# ktor
j
Anyone know how I can expose members to routes / application?
c
Could you please explain? What exact members are you talking about?
j
Copy code
fun Application.main() {
    install(CallLogging)

    routing {
        get("/") {
            call.respondText("""Hello, world!<br><a href="/bye">Say bye?</a>""", ContentType.Text.Html)
        }
        get("/bye") {
            call.respondText("""Good bye!""", ContentType.Text.Html)
        }
    }
}

fun Http(host: String, port: Int) = embeddedServer(Netty, host = host, port = port, module=Application::main)
`
I have a
SendChannel<Any>
that I want exposed to routes. so I can then call
channel.send("test")
for example
c
Why can't you simply capture it inside of routing lambda?
j
because its defined outside of application and used elsewhere in the project
c
Don't you start the relevant component inside of the module start function?
val facade = startEventConsumer(this)
The other alternative is to make a feature that could be installed to the application via
install(MyEventBus)
and that could be retrieved via
application.feature(MyEventBus)
j
Because the consumer is shared between multiple components, ktor for http and zmq for wire transport
Found a way to achieve what I want.
Copy code
fun Http(host: String, port: Int) = embeddedServer(Netty, host = host, port = port) {
    install(CallLogging)
    
    routing {
        get("/") {
            call.respondText("""Hello, world!<br><a href="/bye">Say bye?</a>""", ContentType.Text.Html)
        }
        get("/bye") {
            call.respondText("""Good bye!""", ContentType.Text.Html)
        }
    }
}