本文整理汇总了Java中org.springframework.web.reactive.function.client.WebClient.create方法的典型用法代码示例。如果您正苦于以下问题:Java WebClient.create方法的具体用法?Java WebClient.create怎么用?Java WebClient.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.reactive.function.client.WebClient
的用法示例。
在下文中一共展示了WebClient.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hystrixStreamWorks
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Test
public void hystrixStreamWorks() {
String url = "http://localhost:" + port;
// you have to hit a Hystrix circuit breaker before the stream sends anything
WebTestClient testClient = WebTestClient.bindToServer().baseUrl(url).build();
testClient.get().uri("/").exchange().expectStatus().isOk();
WebClient client = WebClient.create(url);
Flux<String> result = client.get().uri(BASE_PATH + "/hystrix.stream")
.accept(MediaType.TEXT_EVENT_STREAM)
.exchange()
.flatMapMany(res -> res.bodyToFlux(Map.class))
.take(5)
.filter(map -> "HystrixCommand".equals(map.get("type")))
.map(map -> (String)map.get("type"));
StepVerifier.create(result)
.expectNext("HystrixCommand")
.thenCancel()
.verify();
}
示例2: setup
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Before
public void setup(){
request = mock(ServerRequest.class);
serviceLocator = mock(ReactiveBankServiceLocator.class);
reactorLoanBrokerAgent = new ReactorLoanBrokerAgent(serviceLocator,WebClient.create(new ReactorClientHttpConnector()));
loanBrokerHandler = new LoanBrokerHandler(reactorLoanBrokerAgent);
}
示例3: main
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
public static final void main(String[] args) throws IOException {
WebClient client = WebClient.create("http://localhost:8080");
client
.get()
.uri("/posts")
.exchange()
.flatMapMany(res -> res.bodyToFlux(Post.class))
.log()
.subscribe(post -> System.out.println("post: " + post));
System.out.println("Client is started!");
System.in.read();
}
示例4: main
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
public static void main(String[] args) {
// RestClientCoinbase client = new RestClientCoinbase();
// client.testIt();
WebClient wc = WebClient.create(URL);
QuoteCb quoteCb = wc.get().uri("/exchange-rates?currency=BTC")
.accept(MediaType.APPLICATION_JSON_UTF8).exchange()
.flatMap(response -> response.bodyToMono(WrapperCb.class))
.flatMap(resp -> Mono.just(resp.getData()))
.flatMap(resp2 -> Mono.just(resp2.getRates()))
.block();
System.out.println(quoteCb.toString());
}
示例5: main
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
public static void main(String[] args) {
WebClient wc = WebClient.create(URL);
QuoteBs quote = wc.get().uri("/v2/ticker/xrpeur/")
.accept(MediaType.APPLICATION_JSON).exchange().flatMap(response -> response.bodyToMono(QuoteBs.class))
.map(res -> {res.setPair("xrpeur");return res;}).block();
System.out.println(quote.toString());
}
示例6: myCommandLineRunner
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Bean
public CommandLineRunner myCommandLineRunner() {
return args -> {
String api = "http://stockmarket.streamdata.io/prices";
String token = "[YOUR TOKEN HERE]";
// If ever you want to pass some headers to your API
// specify a header map associated with the request
Map<String,String> headers = new HashMap<>();
// add this header if you wish to stream Json rather than Json-patch
// NOTE: no 'patch' event will be emitted.
// headers.put("Accept", "application/json");
URI streamdataUri = streamdataUri(api, token, headers);
// source: https://github.com/spring-projects/spring-framework/blob/v5.0.0.RC1/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java
ResolvableType type = forClassWithGenerics(ServerSentEvent.class, JsonNode.class);
// Create the web client and the flux of events
WebClient client = WebClient.create();
Flux<ServerSentEvent<JsonNode>> events =
client.get()
.uri(streamdataUri)
.accept(TEXT_EVENT_STREAM)
.exchange()
.flatMapMany(response -> response.body(toFlux(type)));
// use of a transformer to apply the patches
events.as(new PatchTransformer())
// Subscribe to the flux with a consumer that applies patches
.subscribe(System.out::println,
Throwable::printStackTrace);
// Add a block here because CommandLineRunner returns after the execution of the code
// ... and make the code run 1 day.
Mono.just("That's the end!")
.delayElement(Duration.ofDays(1))
.block();
};
}
开发者ID:streamdataio,项目名称:streamdataio-spring-webflux,代码行数:40,代码来源:StreamdataioSpringWebfluxApplication.java
示例7: setup
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Before
public void setup() {
//TODO: how to set new ReactorClientHttpConnector()
baseUri = "http://localhost:" + port;
this.webClient = WebClient.create(baseUri);
this.testClient = WebTestClient.bindToServer().baseUrl(baseUri).build();
}
示例8: webClient
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Bean
public WebClient webClient(){
return WebClient.create(new ReactorClientHttpConnector());
}
示例9: webClient
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Bean
public WebClient webClient(){
return WebClient.create();
}
示例10: setup
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Before
public void setup() {
this.webClient = WebClient.create("http://localhost:" + this.port);
}
示例11: webclient
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Bean
WebClient webclient() {
return WebClient.create();
}
示例12: GeoLocationServiceImpl
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
public GeoLocationServiceImpl(final String endPoint) {
this.endPoint = endPoint;
this.webClient = WebClient.create();
}
示例13: SunriseSunsetServiceImpl
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
public SunriseSunsetServiceImpl(final String endPoint) {
this.endPoint = endPoint;
this.webClient = WebClient.create();
}
示例14: login
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
private Mono<VaultToken> login(AuthenticationSteps steps) {
AuthenticationStepsOperator operator = new AuthenticationStepsOperator(steps,
WebClient.create());
return operator.getVaultToken();
}
示例15: webClient
import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Bean WebClient webClient() {
return WebClient.create();
}