Reputation: 41
I am testing RSocket request-response logic and have some problem with processing headers.
I am using spring boot 2.7.9 with Kotlin.
My Controller:
package com.mol.rsocket.controller
import com.mol.rsocket.model.HelloRequest
import org.springframework.messaging.handler.annotation.Headers
import org.springframework.messaging.handler.annotation.MessageMapping
import org.springframework.stereotype.Controller
import reactor.core.publisher.Mono
import reactor.kotlin.core.publisher.toMono
@Controller
class Controller {
@MessageMapping("hello")
fun currentMarketData(
request: HelloRequest,
@Headers headers: Map<String, String>,
): Mono<String> {
println("Headers ${headers.keys}")
return "Hello ${request.name}!!".toMono()
}
}
And my build.gradle
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.7.9"
id("io.spring.dependency-management") version "1.0.15.RELEASE"
kotlin("jvm") version "1.6.21"
kotlin("plugin.spring") version "1.6.21"
}
group = "com.mol"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-rsocket")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
For testing requests I use rsocket-cli and my request looks like:
rsocket-cli --route=hello -i "{\"name\": \"Kirill\"}" --header foo:bar --header hello:world --request tcp://localhost:7000
So in the console I don't see my headers keys. Only this:
Headers [dataBufferFactory, rsocketRequester, rsocketResponse, lookupDestination, contentType, rsocketFrameType]
I found some information about extracting headers here, but it doesn't helps me https://docs.spring.io/spring-framework/docs/current/reference/html/rsocket.html
Upvotes: 2
Views: 135