本文整理汇总了Java中io.reactivex.netty.protocol.http.server.HttpServer.getServerPort方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServer.getServerPort方法的具体用法?Java HttpServer.getServerPort怎么用?Java HttpServer.getServerPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.netty.protocol.http.server.HttpServer
的用法示例。
在下文中一共展示了HttpServer.getServerPort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import io.reactivex.netty.protocol.http.server.HttpServer; //导入方法依赖的package包/类
@Test
public void test() {
// create protocol with handlers
ReactiveSocketWebSocketServer handler = ReactiveSocketWebSocketServer.create(
requestResponsePayload -> {
String requestResponse = byteToString(requestResponsePayload.getData());
return Single.just(utf8EncodedPayloadData("hello" + requestResponse));
} ,
requestStreamPayload -> {
String requestStream = byteToString(requestStreamPayload.getData());
return just("a_" + requestStream, "b_" + requestStream).map(n -> utf8EncodedPayloadData(n));
} , null, null, null);
// start server with protocol
HttpServer<ByteBuf, ByteBuf> server = HttpServer.newServer();
int port = server.getServerPort();
server.start((request, response) -> {
return response.acceptWebSocketUpgrade(handler::acceptWebsocket);
});
// TODO send actual requests
HttpClient.newClient("localhost", server.getServerPort())
.createGet("/")
.requestWebSocketUpgrade();
server.shutdown();
}
开发者ID:NiteshKant,项目名称:reactivesocket-websocket-rxnetty,代码行数:28,代码来源:ReactiveSocketWebSocketServerTest.java
示例2: main
import io.reactivex.netty.protocol.http.server.HttpServer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
final int eurekaReadServerPort = 7005;
final int eurekaWriteServerPort = 7006;
/**
* Starts an embedded eureka server with the defined read and write ports.
*/
startEurekaServer(eurekaReadServerPort, eurekaWriteServerPort);
/**
* Create eureka client with the same read and write ports for the embedded eureka server.
*/
EurekaClient eurekaClient = createEurekaClient(eurekaReadServerPort, eurekaWriteServerPort);
/**
* Reuse {@link ClientServer} example to start an RxNetty server on the passed port.
*/
HttpServer<ByteBuf, ByteBuf> server = ClientServer.startServer(8089);
/**
* Register the server started above with eureka using a unique virtual IP address (VIP).
* Eureka uses VIPs to group homogeneous instances of a service together, so that they can be used by clients,
* interchangeably.
*/
String vipAddress = "mock_server-" + server.getServerPort();
registerWithEureka(server.getServerPort(), eurekaClient, vipAddress);
/**
* Retrieve the instance information of the registered server from eureka.
* This is to demonstrate how to use eureka to fetch information about any server in your deployment.
* In order to fetch information from eureka, one MUST know the VIP address of the server before hand.
*/
InstanceInfo serverInfo = getServerInfo(eurekaClient, vipAddress);
/**
* Retrieve IPAddress and port information from the instance information returned from eureka.
*/
Host host = getServerHostAndPort(serverInfo);
/**
* Reuse {@link ClientServer} example to create an HTTP request to the server retrieved from eureka.
*/
ClientServer.createRequest(host.getIpAddress(), host.getPort())
/* Block till you get the response. In a real world application, one should not be blocked but chained
* into a response to the caller. */
.toBlocking()
/**
* Print each content of the response.
*/
.forEach(System.out::println);
}
示例3: main
import io.reactivex.netty.protocol.http.server.HttpServer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
final int eurekaReadServerPort = 7008;
final int eurekaWriteServerPort = 7010;
/**
* Starts an embedded eureka server with the defined read and write ports.
*/
ClientServerWithDiscovery.startEurekaServer(eurekaReadServerPort, eurekaWriteServerPort);
/**
* Create eureka client with the same read and write ports for the embedded eureka server.
*/
EurekaClient eurekaClient = ClientServerWithDiscovery.createEurekaClient(eurekaReadServerPort,
eurekaWriteServerPort);
/**
* Reuse {@link ClientServer} example to start an RxNetty server on the passed port.
*/
HttpServer<ByteBuf, ByteBuf> server = ClientServer.startServer(8089);
/**
* Register the server started above with eureka using a unique virtual IP address (VIP).
* Eureka uses VIPs to group homogeneous instances of a service together, so that they can be used by clients,
* interchangeably.
*/
String vipAddress = "mock_server-" + server.getServerPort();
ClientServerWithDiscovery.registerWithEureka(server.getServerPort(), eurekaClient, vipAddress);
/**
* Using the eureka client, create an Ocelli Host event stream.
* Ocelli, uses this host stream to know about the available hosts.
*/
Observable<MembershipEvent<Host>> eurekaHostSource = ClientServerWithLoadBalancer.createEurekaHostStream(
eurekaClient, vipAddress);
MyCommand myCommand = new MyCommand(eurekaHostSource);
/**
* This executes the request on the client (just as {@link ClientServerWithLoadBalancer} but using hystrix.
*/
myCommand.toObservable()
/* Block till you get the response. In a real world application, one should not be blocked but chained
* into a response to the caller. */
.toBlocking()
/**
* Print each content of the response.
*/
.forEach(System.out::println);
}
示例4: main
import io.reactivex.netty.protocol.http.server.HttpServer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
final int eurekaReadServerPort = 7007;
final int eurekaWriteServerPort = 7008;
/**
* Starts an embedded eureka server with the defined read and write ports.
*/
ClientServerWithDiscovery.startEurekaServer(eurekaReadServerPort, eurekaWriteServerPort);
/**
* Create eureka client with the same read and write ports for the embedded eureka server.
*/
EurekaClient eurekaClient = ClientServerWithDiscovery.createEurekaClient(eurekaReadServerPort,
eurekaWriteServerPort);
/**
* Reuse {@link ClientServer} example to start an RxNetty server on the passed port.
*/
HttpServer<ByteBuf, ByteBuf> server = ClientServer.startServer(8089);
/**
* Register the server started above with eureka using a unique virtual IP address (VIP).
* Eureka uses VIPs to group homogeneous instances of a service together, so that they can be used by clients,
* interchangeably.
*/
String vipAddress = "mock_server-" + server.getServerPort();
ClientServerWithDiscovery.registerWithEureka(server.getServerPort(), eurekaClient, vipAddress);
/**
* Using the eureka client, create an Ocelli Host event stream.
* Ocelli, uses this host stream to know about the available hosts.
*/
Observable<MembershipEvent<Host>> eurekaHostSource = createEurekaHostStream(eurekaClient, vipAddress);
/**
* Instead of directly using the host and port from eureka as in example {@link ClientServerWithDiscovery},
* choose a host from the load balancer.
*/
createRequestFromLB(eurekaHostSource)
/* Block till you get the response. In a real world application, one should not be blocked but chained
* into a response to the caller. */
.toBlocking()
/**
* Print each content of the response.
*/
.forEach(System.out::println);
}