Comments (6)
@halimpuckjava if you use Spring RSocket with Spring Boot, then you should use Spring's RSocketRequester to call RSocket Service and link is https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#rsocket-requester
from rsocket.
@linux-china thanks for response
yes i know with RSocketRequester you can resolve this issue, so if my client is android or desktop how i can communicate with spring boot rsocket without add RSocketRequester to client dependencies ?
with RSocketRequester you can specify distination (path of handler) with route(), however rsocket don"t have this feature
from rsocket.
@halimpuckjava you can refer following code.
import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.CompositeByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.rsocket.RSocket;
import io.rsocket.RSocketFactory;
import io.rsocket.metadata.CompositeMetadataFlyweight;
import io.rsocket.metadata.TaggingMetadataFlyweight;
import io.rsocket.metadata.WellKnownMimeType;
import io.rsocket.uri.UriTransportRegistry;
import io.rsocket.util.DefaultPayload;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.Collections;
public class RSocketClientTest {
private ObjectMapper objectMapper = new ObjectMapper();
private static RSocket rsocket;
@BeforeAll
public static void setUp() throws Exception {
rsocket = RSocketFactory
.connect()
.dataMimeType(WellKnownMimeType.APPLICATION_JSON.getString())
.metadataMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString())
.transport(UriTransportRegistry.clientForUri("ws://127.0.0.1:8088/rsocket"))
.start()
.block();
}
@AfterAll
public static void tearDown() {
rsocket.dispose();
}
@Test
public void testRequestResponse() throws Exception {
CompositeByteBuf compositeByteBuf = compositeMetadataWithRouting("org.mvnsearch.account.AccountService.findById");
byte[] jsonData = objectMapper.writeValueAsBytes(1);
rsocket.requestResponse(DefaultPayload.create(Unpooled.wrappedBuffer(jsonData), compositeByteBuf))
.subscribe(payload -> {
System.out.println(payload.getDataUtf8());
});
Thread.sleep(500000);
}
private CompositeByteBuf compositeMetadataWithRouting(String routingKey) {
PooledByteBufAllocator allocator = PooledByteBufAllocator.DEFAULT;
CompositeByteBuf compositeByteBuf = allocator.compositeDirectBuffer();
ByteBuf routingMetadata = TaggingMetadataFlyweight.createTaggingContent(allocator, Collections.singletonList(routingKey));
CompositeMetadataFlyweight.encodeAndAddMetadata(compositeByteBuf, allocator, WellKnownMimeType.MESSAGE_RSOCKET_ROUTING, routingMetadata);
return compositeByteBuf;
}
}
Just three things:
- Call ".dataMimeType(WellKnownMimeType.APPLICATION_JSON.getString())" to connect Spring Boot RSocket Service, and payload's bytes data should be encoded with this type for next calls.
- Create a composite metadata with routing info for Payload and method is compositeMetadataWithRouting
- Check Spring RSocket document to choose correct RSocket call: resquestResponse, requestStream, fireAndForget and requestChannel
from rsocket.
@halimpuckjava my bad. you are using rsocket-kotlin to call Spring Boot RSocket service, and you can construct basic composite metadata to implement routing.
from rsocket.
@linux-china thanks
from rsocket.
closing this one as not recent activity
from rsocket.
Related Issues (20)
- [Release] Checklist HOT 7
- Cannot dispose server HOT 2
- Fragmentation for METADATA_PUSH HOT 4
- NET::ERR_CERT_COMMON_NAME_INVALID HOT 6
- [Needs Clarification] Frame Size Limit
- Weaker frame ordering in Connection-Oriented communication HOT 24
- Dart/Flutter support. HOT 6
- Re-vice spec format to be aligned with RFC format
- The successor of websocket is being worked on HOT 5
- Jitter for KEEP ALIVE frames HOT 5
- RSocket has /will consider request-reponse as a default mode? HOT 2
- Signup link for community.reactive.foundation breaks on community.netifi.com redirect HOT 1
- Add Connection Setup frame to list of places where composite metadata can be applied
- Deploy rsocket-demo as demo.rsocket.io
- [Discussion] Does rsocket plan to be supported by cloud native components? HOT 3
- Propagate headers/metadata in RSocket HOT 1
- rsocket send duplicate requests (4) each "keepAlive" interval HOT 1
- Confusion on metadata length field
- MimeType of MESSAGE_RSOCKET_AUTHENTICATION does not work with JWTs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rsocket.