当前位置: 首页>>代码示例>>Java>>正文


Java WebClient.create方法代码示例

本文整理汇总了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();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:23,代码来源:HystrixWebfluxEndpointTests.java

示例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);
}
 
开发者ID:noorulhaq,项目名称:reactive.loanbroker.system,代码行数:8,代码来源:LoanBrokerTests.java

示例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();
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:14,代码来源:DemoClient.java

示例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());
		
	}
 
开发者ID:Angular2Guy,项目名称:AngularAndSpring,代码行数:14,代码来源:RestClientCoinbase.java

示例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());
}
 
开发者ID:Angular2Guy,项目名称:AngularAndSpring,代码行数:8,代码来源:RestClientBitstamp.java

示例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();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:8,代码来源:BaseWebClientTests.java

示例8: webClient

import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Bean
public WebClient webClient(){
	return WebClient.create(new ReactorClientHttpConnector());
}
 
开发者ID:noorulhaq,项目名称:reactive.loanbroker.system,代码行数:5,代码来源:Application.java

示例9: webClient

import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Bean
public WebClient webClient(){
    return WebClient.create();
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:5,代码来源:IntegrationConfig.java

示例10: setup

import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Before
public void setup() {
	this.webClient = WebClient.create("http://localhost:" + this.port);
}
 
开发者ID:callistaenterprise,项目名称:spring-react-one,代码行数:5,代码来源:ReactiveSampleApplicationTests.java

示例11: webclient

import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Bean
WebClient webclient() {
  return WebClient.create();
}
 
开发者ID:amoAHCP,项目名称:openshift-workshop,代码行数:5,代码来源:FrontendApplication.java

示例12: GeoLocationServiceImpl

import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
public GeoLocationServiceImpl(final String endPoint) {
    this.endPoint = endPoint;
    this.webClient = WebClient.create();
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:5,代码来源:GeoLocationServiceImpl.java

示例13: SunriseSunsetServiceImpl

import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
public SunriseSunsetServiceImpl(final String endPoint) {
    this.endPoint = endPoint;
    this.webClient = WebClient.create();
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:5,代码来源:SunriseSunsetServiceImpl.java

示例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();
	}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:7,代码来源:AuthenticationStepsOperatorUnitTests.java

示例15: webClient

import org.springframework.web.reactive.function.client.WebClient; //导入方法依赖的package包/类
@Bean WebClient webClient() {
	return WebClient.create();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:4,代码来源:TraceWebFluxTests.java


注:本文中的org.springframework.web.reactive.function.client.WebClient.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。