本文整理汇总了Java中com.netflix.hystrix.HystrixCommand.execute方法的典型用法代码示例。如果您正苦于以下问题:Java HystrixCommand.execute方法的具体用法?Java HystrixCommand.execute怎么用?Java HystrixCommand.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.hystrix.HystrixCommand
的用法示例。
在下文中一共展示了HystrixCommand.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateColumn
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@RequestMapping(value = "/api/datasets/{datasetId}/column/{columnId}", method = POST, consumes = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Update a dataset.", consumes = APPLICATION_JSON_VALUE, //
notes = "Update a data set based on content provided in POST body with given id. For documentation purposes, body is typed as 'text/plain' but operation accepts binary content too.")
@Timed
public void updateColumn(@PathVariable(value = "datasetId") @ApiParam(value = "Id of the dataset to update") final String datasetId,
@PathVariable(value = "columnId") @ApiParam(value = "Id of the column to update") final String columnId,
@ApiParam(value = "content") final InputStream body) {
if (LOG.isDebugEnabled()) {
LOG.debug("Creating or updating dataset #{} (pool: {})...", datasetId, getConnectionStats());
}
final HystrixCommand<Void> creation = getCommand(UpdateColumn.class, datasetId, columnId, body);
creation.execute();
LOG.debug("Dataset creation or update for #{} done.", datasetId);
}
示例2: execute
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@Override
public HystrixCommand<T> execute(EndpointCall<R> call, Object[] args) {
return new HystrixCommand<T>(hystrixMetadata()) {
@Override
protected T run() throws Exception {
return delegate.execute(call, args);
}
protected T getFallback() {
return fallback == null ? super.getFallback() : doFallback();
}
private T doFallback() {
HystrixCommandFallback hystrixCommandFallback = Optional.ofNullable(fallback)
.map(f -> new HystrixCommandFallback(endpointMethod, args, fallback))
.orElse(null);
HystrixCommand<T> value = hystrixCommandFallback.run();
return value.execute();
};
};
}
示例3: mailTo
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@RequestMapping(value = "/api/mail", method = PUT)
@ApiOperation(value = "Send feedback to Talend")
@Timed
public void mailTo(@RequestBody MailDetails mailDetails) {
if (mailDetails.isEmpty()) {
throw new TDPException(APIErrorCodes.UNABLE_TO_GET_MAIL_DETAILS);
}
try {
final HystrixCommand<Void> sendFeedback = getCommand(MailToCommand.class, mailDetails);
sendFeedback.execute();
} catch (Exception e) {
throw new TDPException(APIErrorCodes.UNABLE_TO_SEND_MAIL, e);
}
}
示例4: create
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
/**
* Create a dataset from request body content.
*
* @param name The dataset name.
* @param contentType the request content type used to distinguish dataset creation or import.
* @param dataSetContent the dataset content from the http request body.
* @return The dataset id.
*/
@RequestMapping(value = "/api/datasets", method = POST, produces = TEXT_PLAIN_VALUE)
@ApiOperation(value = "Create a data set", produces = TEXT_PLAIN_VALUE, notes = "Create a new data set based on content provided in POST body. For documentation purposes, body is typed as 'text/plain' but operation accepts binary content too. Returns the id of the newly created data set.")
@Timed
public Callable<String> create(
@ApiParam(value = "User readable name of the data set (e.g. 'Finance Report 2015', 'Test Data Set').") @RequestParam(defaultValue = "", required = false) String name,
@ApiParam(value = "An optional tag to be added in data set metadata once created.") @RequestParam(defaultValue = "", required = false) String tag,
@ApiParam(value = "Size of the data set, in bytes.") @RequestParam(defaultValue = "0") long size,
@RequestHeader(CONTENT_TYPE) String contentType, @ApiParam(value = "content") InputStream dataSetContent) {
return () -> {
if (LOG.isDebugEnabled()) {
LOG.debug("Creating dataset (pool: {} )...", getConnectionStats());
}
try {
HystrixCommand<String> creation = getCommand(CreateDataSet.class, name, tag, contentType, size, dataSetContent);
return creation.execute();
} finally {
LOG.debug("Dataset creation done.");
}
};
}
示例5: testHystrixSetterFactory
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@Test
public void testHystrixSetterFactory() {
HystrixCommand<List<Hello>> command = this.hystrixSetterFactoryClient
.getHellosHystrix();
assertNotNull("command was null", command);
String setterPrefix = TestHystrixSetterFactoryClientConfig.SETTER_PREFIX;
assertEquals(
"Hystrix command group name should match the name of the feign client with a prefix of "
+ setterPrefix, setterPrefix + "localapp5",
command.getCommandGroup().name());
assertEquals(
"Hystrix command key name should match the request method (space) request path with a prefix of "
+ setterPrefix, setterPrefix + "GET /hellos",
command.getCommandKey().name());
List<Hello> hellos = command.execute();
assertNotNull("hellos was null", hellos);
assertEquals("hellos didn't match", hellos, getHelloList());
}
示例6: update
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@RequestMapping(value = "/api/datasets/{id}", method = POST, produces = TEXT_PLAIN_VALUE)
@ApiOperation(value = "Update a dataset.", produces = TEXT_PLAIN_VALUE, //
notes = "Update a data set based on content provided in POST body with given id. For documentation purposes, body is typed as 'text/plain' but operation accepts binary content too.")
@Timed
public Callable<String> update(@ApiParam(value = "Id of the data set to update / create") @PathVariable(value = "id") String id,
@ApiParam(value = "content") InputStream dataSetContent) {
return () -> {
if (LOG.isDebugEnabled()) {
LOG.debug("Creating or updating dataset #{} (pool: {})...", id, getConnectionStats());
}
HystrixCommand<String> creation = getCommand(UpdateDataSet.class, id, dataSetContent);
String result = creation.execute();
LOG.debug("Dataset creation or update for #{} done.", id);
return result;
};
}
示例7: itShouldCreateDeviceCertificateSuccessfully
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@Test
public void itShouldCreateDeviceCertificateSuccessfully() {
DeviceCertClient sut = Clients.simpleDeviceCertClient(BASE_ENDPOINT);
CreateDeviceCertificateRequestDto request = CreateDeviceCertificateRequestDto.builder()
.devicePublicKey(ANY_PUBLIC_KEY)
.build();
HystrixCommand<CreateDeviceCertificateResponseDto> deviceCertificateRequest = sut
.createDeviceCertificate(DEMO_APP_ID, DEMO_API_KEY, request);
CreateDeviceCertificateResponseDto deviceCertificateResponse = deviceCertificateRequest.execute();
assertThat(deviceCertificateResponse, is(notNullValue()));
}
示例8: itShouldCreateDeviceCertificateSuccessfully
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@Test
public void itShouldCreateDeviceCertificateSuccessfully() throws JsonProcessingException {
CreateDeviceCertificateResponseDto deviceCertificate = CreateDeviceCertificateResponseDtoObjectMother.random();
String deviceCertificateAsJson = Clients.defaultObjectMapper.writeValueAsString(deviceCertificate);
MockClient mockClient = new MockClient()
.add(HttpMethod.POST, "/api/v1/device_certificates", Response.builder()
.status(HttpStatus.CREATED.value())
.reason(HttpStatus.CREATED.getReasonPhrase())
.headers(Collections.<String, Collection<String>>emptyMap())
.body(deviceCertificateAsJson, Charsets.UTF_8));
Target<DeviceCertClient> mockTarget = new MockTarget<DeviceCertClient>(DeviceCertClient.class);
DeviceCertClient sut = Clients.simpleFeignBuilder()
.client(mockClient)
.build()
.newInstance(mockTarget);
CreateDeviceCertificateRequestDto request = CreateDeviceCertificateRequestDto.builder()
.build();
HystrixCommand<CreateDeviceCertificateResponseDto> deviceCertificateRequest = sut
.createDeviceCertificate(RANDOM_APP_ID, RANDOM_API_KEY, request);
CreateDeviceCertificateResponseDto deviceCertificateResponse = deviceCertificateRequest.execute();
assertThat(deviceCertificateResponse, is(notNullValue()));
assertThat(deviceCertificateResponse.getDeviceCertificate(), is(deviceCertificate.getDeviceCertificate()));
}
示例9: itShouldFetchAccessCertificatesSuccessfully
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@Test
public void itShouldFetchAccessCertificatesSuccessfully() throws JsonProcessingException {
GetAccessCertificatesResponseDto accessCertificatesResponseDto = GetAccessCertificatesResponseDtoObjectMother.random();
String accessCertificatesResponseDtoAsJson = Clients.defaultObjectMapper.writeValueAsString(accessCertificatesResponseDto);
MockClient mockClient = new MockClient()
.add(HttpMethod.GET, String.format("/api/v1/device/%s/access_certificates", RANDOM_DEVICE_SERIAL), Response.builder()
.status(HttpStatus.OK.value())
.reason(HttpStatus.OK.getReasonPhrase())
.headers(Collections.<String, Collection<String>>emptyMap())
.body(accessCertificatesResponseDtoAsJson, Charsets.UTF_8));
Target<AccessCertClient> mockTarget = new MockTarget<AccessCertClient>(AccessCertClient.class);
AccessCertClient sut = Clients.simpleFeignBuilder()
.client(mockClient)
.build()
.newInstance(mockTarget);
HystrixCommand<GetAccessCertificatesResponseDto> accessCertificatesRequest = sut
.fetchAccessCertificates("", "", RANDOM_DEVICE_SERIAL);
GetAccessCertificatesResponseDto accessCertificatesResponse = accessCertificatesRequest.execute();
assertThat(accessCertificatesResponse, is(notNullValue()));
assertThat(accessCertificatesResponse, is(accessCertificatesResponseDto));
assertThat(accessCertificatesResponse.getAccessCertificates(), hasSize(accessCertificatesResponseDto.getAccessCertificates().size()));
}
示例10: shouldPropagateExceptionWhenHystrixCommandThrowsException
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@Test(expected = HystrixRuntimeException.class)
public void shouldPropagateExceptionWhenHystrixCommandThrowsException() throws Exception {
EndpointCallExecutable<HystrixCommand<String>, String> executable = factory
.create(new SimpleEndpointMethod(SomeType.class.getMethod("command")), delegate);
HystrixCommand<String> hystrixCommand = executable.execute(() -> {throw new RuntimeException("oooh!");}, null);
hystrixCommand.execute();
}
开发者ID:ljtfreitas,项目名称:java-restify,代码行数:10,代码来源:HystrixCommandEndpointCallExecutableFactoryTest.java
示例11: shouldGetFallbackToBadApiWhenHystrixCommandIsCalled
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@Test
public void shouldGetFallbackToBadApiWhenHystrixCommandIsCalled() {
mockApiServer.expect(requestTo("http://localhost:8080/bad/get"))
.andExpect(method(HttpMethod.GET))
.andRespond(withServerError());
HystrixCommand<String> command = badApi.getAsHystrixCommand();
String result = command.execute(); // break (response is 500) -> go to fallback...
// see FallbackBadApi class
assertEquals("this is BadApi (command) fallback!", result);
}
示例12: shouldGetNormalResultOfGoodApiWhenHystrixCommandIsCalled
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@Test
public void shouldGetNormalResultOfGoodApiWhenHystrixCommandIsCalled() {
mockApiServer.expect(requestTo("http://localhost:8080/good/get"))
.andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("It's works!", MediaType.TEXT_PLAIN));
HystrixCommand<String> command = goodApi.getAsHystrixCommand();
String result = command.execute(); // response is 200
assertEquals("It's works!", result);
}
示例13: invoke
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@Override
public Object invoke(Object o, Method method, Object[] args) throws Throwable {
String methodKey = method.getName() + ":" + method.getReturnType().getCanonicalName();
if ("equals".equals(method.getName())) {
return equals(args[0]);
} else if ("hashCode".equals(method.getName())) {
return hashCode();
} else if ("toString".equals(method.getName())) {
return toString();
}
if (!methodsToInvoke.containsKey(methodKey)) {
throw new RuntimeException("Undefined method called: " + method.getName());
}
HystrixCommand<Object> hystrixCommand = new HystrixCommand<Object>(setters.get(methodKey)) {
@Override
protected Object run() throws Exception {
try {
MethodMetadata invokableMethod = methodsToInvoke.get(methodKey);
return invokableMethod.invoke(proxyService, args);
} catch (Exception e) {
throw e;
} catch (Throwable t) {
throw (Error) t;
}
}
};
if (isReturnsHystrixCommand(method)) {
return hystrixCommand;
} else if (isReturnsObservable(method)) {
return hystrixCommand.toObservable();
} else if (isReturnsSingle(method)) {
return hystrixCommand.toObservable().toSingle();
} else {
return hystrixCommand.execute();
}
}
示例14: should_pass_tracing_information_when_using_Hystrix_commands
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@Test
public void should_pass_tracing_information_when_using_Hystrix_commands() {
Tracer tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
new DefaultSpanNamer(), new NoOpSpanLogger(), new NoOpSpanReporter());
TraceKeys traceKeys = new TraceKeys();
HystrixCommand.Setter setter = HystrixCommand.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("group"))
.andCommandKey(HystrixCommandKey.Factory.asKey("command"));
// tag::hystrix_command[]
HystrixCommand<String> hystrixCommand = new HystrixCommand<String>(setter) {
@Override
protected String run() throws Exception {
return someLogic();
}
};
// end::hystrix_command[]
// tag::trace_hystrix_command[]
TraceCommand<String> traceCommand = new TraceCommand<String>(tracer, traceKeys, setter) {
@Override
public String doRun() throws Exception {
return someLogic();
}
};
// end::trace_hystrix_command[]
String resultFromHystrixCommand = hystrixCommand.execute();
String resultFromTraceCommand = traceCommand.execute();
then(resultFromHystrixCommand).isEqualTo(resultFromTraceCommand);
then(tracer.getCurrentSpan()).isNull();
}
示例15: should_pass_tracing_information_when_using_Hystrix_commands
import com.netflix.hystrix.HystrixCommand; //导入方法依赖的package包/类
@Test
public void should_pass_tracing_information_when_using_Hystrix_commands() {
Tracer tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
new DefaultSpanNamer(), new NoOpSpanLogger(), new NoOpSpanReporter(), new TraceKeys());
TraceKeys traceKeys = new TraceKeys();
HystrixCommand.Setter setter = withGroupKey(asKey("group"))
.andCommandKey(HystrixCommandKey.Factory.asKey("command"));
// tag::hystrix_command[]
HystrixCommand<String> hystrixCommand = new HystrixCommand<String>(setter) {
@Override
protected String run() throws Exception {
return someLogic();
}
};
// end::hystrix_command[]
// tag::trace_hystrix_command[]
TraceCommand<String> traceCommand = new TraceCommand<String>(tracer, traceKeys, setter) {
@Override
public String doRun() throws Exception {
return someLogic();
}
};
// end::trace_hystrix_command[]
String resultFromHystrixCommand = hystrixCommand.execute();
String resultFromTraceCommand = traceCommand.execute();
then(resultFromHystrixCommand).isEqualTo(resultFromTraceCommand);
then(tracer.getCurrentSpan()).isNull();
}