These are chat archives for spring-cloud/spring-cloud

8th
Aug 2016
Dreampie
@Dreampie
Aug 08 2016 02:41 UTC

hi,if I use @HystrixCommand ThreadLocal can't use,I can't change this isolation.strategy,so how can i use it:

I write callback

private static class SessionCallable<T> implements Callable<T> {
    private final Callable<T> callable;
    private final Session session;

    public SessionCallable(Callable<T> callable) {
      this.callable = callable;
      this.session = sessionTL.get();
    }

    public T call() throws Exception {
      Session original = sessionTL.get();
      sessionTL.set(session);
      try {
        return callable.call();
      } finally {
        sessionTL.set(original);
      }
    }
  }

it's all?

@dsyer
Dreampie
@Dreampie
Aug 08 2016 04:27 UTC
private static class SessionConcurrencyStrategy extends HystrixConcurrencyStrategy {
    public <T> Callable<T> wrapCallable(Callable<T> callable) {
      return new SessionCallable<T>(callable);
    }
  }
Dreampie
@Dreampie
Aug 08 2016 07:41 UTC
public class HystrixRequestContextServletFilter extends OncePerRequestFilter {
  public HystrixRequestContextServletFilter() {
  }

  protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
    HystrixRequestContext context = HystrixRequestContext.initializeContext();
    try {
      chain.doFilter(request, response);
    } finally {
      context.shutdown();
    }
  }
}
Dominik Gätjens
@dcg
Aug 08 2016 13:34 UTC
does anyone has any idea why i got an "org.springframework.cloud.config.server.environment.NoSuchLabelException" "message":"No such label: master" exception if i try to access my Config with Spring-Cloud-Configuration?
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 13:35 UTC
hmm you're not the first one to ask about this
can you file an issue and show the steps to reproduce? Maybe post a sample project?
Dominik Gätjens
@dcg
Aug 08 2016 13:36 UTC
it only happens with a remote git-repo
i have a configuration running that works without problems but i can't realy see a difference
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 13:37 UTC
same versions of libs ?
Dominik Gätjens
@dcg
Aug 08 2016 13:38 UTC
yes im using the Brixton.SR4 BOM
i know that there a some problems with java-ssh clients that don't support all key formats, and i know that sometime dashes are a problem... at the moment i'm trying to change both
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 13:49 UTC
aha - if you manage to post a sample that would be useful
Marcos Barbero
@marcosbarbero
Aug 08 2016 13:52 UTC
I’m not sure if it’s the same problem, but some times I face a issue like that since Angel version.
Using a remote git repository some times it just get stuck and doesn’t checkout the remote git repo. If I do restart the application or clean the /tmp dir on CentOS it just starts to work again.
Dominik Gätjens
@dcg
Aug 08 2016 13:52 UTC
i will try but i guess the problem is that my known hosts uses ecdsa-sha2-nistp256 and afaik jsch only supports ssh-rsa
@marcosbarbero i'm using docker, so i always have a clean state...i'm trying know with ssh-rsa... i will report back if its the problem ;)
Marcos Barbero
@marcosbarbero
Aug 08 2016 13:57 UTC
I see...
I just started to play with docker containers in my applications, I’m still not sure if the behaviour of my issue will keep happening.
Fabian Wallwitz
@cforce
Aug 08 2016 13:58 UTC
what is the best practice to deal with HTTP 400 on FeignClients? I would like NOT to have 400' to trigger a fallback
so i need to intercept the feign http client reponse before returning to the Feign caller method
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:01 UTC
@cforce I think you should implement your own ErrorDecoder but ask in https://gitter.im/OpenFeign/feign
Fabian Wallwitz
@cforce
Aug 08 2016 14:02 UTC
the error decoder won't before the Hystrix (catching alls but 200)
so error decoder is too late
i wil run into the fallback before i have chance to decode the functionals bugs
Spencer Gibb
@spencergibb
Aug 08 2016 14:03 UTC
there’s not much ability to customize the feign/hystrix integration
Dominik Gätjens
@dcg
Aug 08 2016 14:03 UTC
@marcingrzejszczak i found the problem
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:03 UTC
so what was it ?
ah @spencergibb I didn't see we're talking about Hystrix
Fabian Wallwitz
@cforce
Aug 08 2016 14:04 UTC
@spencergibb i i could intercept the http client reponse
Dominik Gätjens
@dcg
Aug 08 2016 14:04 UTC
known_host keys have to be in ssh-rsa format... and all new linux distros use ecdsa-sha2-nistp256
i guess that should be added to the documentation, because it was a hell to debug ;)
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:04 UTC
wow - good to know
Fabian Wallwitz
@cforce
Aug 08 2016 14:04 UTC
@spencergibb similar to "HandlerInterceptorAdapter() ", so i can inspect the reponse HttpServletResponse
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:04 UTC
care to file a PR ? :D
Dominik Gätjens
@dcg
Aug 08 2016 14:05 UTC
to Fix? its a problem in Jsch i guess
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:05 UTC
no - to docs
Dominik Gätjens
@dcg
Aug 08 2016 14:05 UTC
okay, can you provide me a link to the right repo?
Fabian Wallwitz
@cforce
Aug 08 2016 14:05 UTC
i have no idea how i can intercept the FeignClient reponse :(
there is only provided a request interceptor -..
Spencer Gibb
@spencergibb
Aug 08 2016 14:06 UTC
@cforce there is an open PR in feign for that.
Fabian Wallwitz
@cforce
Aug 08 2016 14:06 UTC
which one?
please not the one from Thomas..
that is no solution .. sadly
Spencer Gibb
@spencergibb
Aug 08 2016 14:07 UTC
no idea what your talking about.
the one I’m thinking is by @marcingrzejszczak
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:07 UTC
for the post processors ?
but I'm not catching the response
Fabian Wallwitz
@cforce
Aug 08 2016 14:08 UTC
@spencergibb OpenFeign/feign#431
Spencer Gibb
@spencergibb
Aug 08 2016 14:08 UTC
yeah, don’t know if it would be helpful in the context @cforce needs
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:08 UTC
no - but he can write his own Client impl
Response execute(Request request, Options options) throws IOException;
so he would delegate to the default client impl, catch the exception and do whatever he needs with that
Fabian Wallwitz
@cforce
Aug 08 2016 14:09 UTC
uww.. that is going into the right direction .. tell me more
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:09 UTC
:D
your delegate can be the Client.Default
or whatever you have there
ah in Spring we have the LoadBalancerFeignClient
so you would have to create a post processor that would wrap the existing Client with the logic that you need
we do the same in Sleuth
Fabian Wallwitz
@cforce
Aug 08 2016 14:11 UTC
urgs .. lost me ..
but sound pretty what i should need
;)
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:11 UTC
ok so there is a default Client impl in the context right?
either it's Client.Default or the LoadBalancerFeignClient
so what you need is to wrap that particular Client implementation
Fabian Wallwitz
@cforce
Aug 08 2016 14:12 UTC
i can't see the way how i can @Bean Client client(); how could i
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:12 UTC
hmm exactly as you just said :D
Fabian Wallwitz
@cforce
Aug 08 2016 14:12 UTC
lol
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:12 UTC
@Bean Client client() { return MyClient(); }
but you won't do this casue there already is a Client there in the context
Fabian Wallwitz
@cforce
Aug 08 2016 14:12 UTC
spring (sometimes) is just as easy as it look like
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:13 UTC
so you would have to write a post processor
like this one
and have this if statement in that post processor
and you would basically do return MyClient(this.beanFactory, (Client) bean); or whatever you need there
cause you don't want to override the existing functionality, right?
you want to make feign work with ribbon etc + you'd like it to do some custom stuff @cforce ?
Dominik Gätjens
@dcg
Aug 08 2016 14:19 UTC
@marcingrzejszczak spring-cloud/spring-cloud-config#469
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:20 UTC
ci/pivotal-cla — Please sign the Contributor License Agreement!
Dominik Gätjens
@dcg
Aug 08 2016 14:22 UTC
done
Fabian Wallwitz
@cforce
Aug 08 2016 14:30 UTC
@marcingrzejszczak i want to throw funtional erro on server side as wrapped ExceptionBody (with error code) but 200ok. On FeignClient it will detect the body (of error mime type) and throw unwrapped (error code maps to anotation on exception which are scanned from the Feign inherited server Interface) same exception before Hystrix (works because always http200) or Feign regular client method handler takes place
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:31 UTC
Feign uses load balancing?
Fabian Wallwitz
@cforce
Aug 08 2016 14:31 UTC
sure
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:31 UTC
so by default you'll register
@Bean
    @ConditionalOnMissingBean
    public Client feignClient(CachingSpringLoadBalancerFactory cachingFactory,
            SpringClientFactory clientFactory) {
        return new LoadBalancerFeignClient(new Client.Default(null, null),
                cachingFactory, clientFactory);
    }
Fabian Wallwitz
@cforce
Aug 08 2016 14:31 UTC
hytrix, ribbon .. all in
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:31 UTC
so you need to wrap it with your stuff
that's why you need the beanpostprocessor
congrats @dcg on your first(?) contribution !!!
Fabian Wallwitz
@cforce
Aug 08 2016 14:34 UTC
omg .. not sure if will get working code out of your essence
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:35 UTC
:D
ok I'll help you
let's say that your client will be named MyClient ok?
Fabian Wallwitz
@cforce
Aug 08 2016 14:36 UTC
new stood i want/need to override the "Client" method @Override
public Response execute(Request request, Request.Options options) throws IOException {
the rest is how to inject the overriding into all that spring cloud world
i i have the repsonse in my hand before anything else , i am able to intercept >unwrap > detect possible server side execeptions
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:38 UTC
public MyClient implements Client {
    private final Client delegate;

    public MyClient(Client delegate) {
        this.delegate = delegate;
    }

    @Override public Response execute(Request request, Request.Options options) throws IOException { 
        Response response = this.delegate.execute(...);
        // do whatever you need with that
    }

}

@Bean MyClient myClient() {return new MyClient(); }

class MyClientPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName)
            throws BeansException {
        if (bean instanceof Client && !(bean instanceof MyClient)) {
            return new MyClient((Client) bean);
        }
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName)
            throws BeansException {
        return bean;
    }
}

@Bean MyClientPostProcessor myClientPostProcessor() { return new MyClientPostProcessor(); }
Fabian Wallwitz
@cforce
Aug 08 2016 14:39 UTC
ok
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:39 UTC
of course it's pseudo code - you get the idea
Fabian Wallwitz
@cforce
Aug 08 2016 14:41 UTC
this is injected in the whole application .. if i want to partially only infect some feigns ,, i could inject this into an own @Configuration public class FeignConf {..} class that is used ars paramater at the @FeignClient(configuration= FeignConf .class) .. and FeignConf shall not be part of the component scan, should it?
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 14:42 UTC
hmm I guess it should work - but yo have to check it out
finneym
@finneym
Aug 08 2016 15:11 UTC
Hey everyone, I have a micro service with spring.cloud.config.uri pointing to a config server which is all working fine, I was hoping to also implement a file system based config. Is it possible to just put a local path as a uri that points to wards a configuration?
finneym
@finneym
Aug 08 2016 15:19 UTC
When I say a local path, I also mean that it just points directory to the config, it doesn't use a config server
Stephan L
@stephlag
Aug 08 2016 16:06 UTC
@spencergibb I changed the call from RibbonRoutingFilter to use content length
Marcos Barbero
@marcosbarbero
Aug 08 2016 16:10 UTC
@finneym if your application doesn’t reach to configserver you can externalize your application config files by following the precedence order in this doc. link http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files
will it fit your needs?
Ryan Baxter
@ryanjbaxter
Aug 08 2016 17:50 UTC
@rozhok sorry for not responding to you, i need to get better about paying attention to Gitter…let me know how I can help
bitsofinfo
@bitsofinfo
Aug 08 2016 19:08 UTC
Whats the most effective way to control when a @FeignClient fallback is invoked. Is the fallback invoked only when the response received from the backend service is NOT assignable to the return type on the FeignClient annotated interface? or is it based on response codes.
Ryan Baxter
@ryanjbaxter
Aug 08 2016 19:11 UTC
@bitsofinfo i have been in that code a little bit lately, and I think it is just based on the fact an exception is thrown
Hystrix does not really care why the exception is thrown
bitsofinfo
@bitsofinfo
Aug 08 2016 19:12 UTC
k, thanks man
Ryan Baxter
@ryanjbaxter
Aug 08 2016 19:12 UTC
for example the protected call might not even be making a remote call over the network
Marcin Grzejszczak
@marcingrzejszczak
Aug 08 2016 19:28 UTC
It also depends on whether you have hystrix or not
Cause it then depends on impl of error decoder and client AFAIR
Ah were taking about fallback
Ignore me
Daniel Lavoie
@daniellavoie
Aug 08 2016 20:18 UTC

Hello guys ! Was about time I join Gitter/Spring-Cloud

You guys been following Zuul 2 a little bit ? Too bad the guys at Netflix didn't considered reactor ;)

Daniel Lavoie
@daniellavoie
Aug 08 2016 21:12 UTC
@ryanjbaxter You are working on dropping Travis for Circle CI ? Travis is getting worse and worse :worried:
ccit-spence
@ccit-spence
Aug 08 2016 21:22 UTC
Has anyone tried to use a dynamic container port in conjunction with a dynamic host port with docker for a spring cloud service? server.port=0 with -P?
This is using --net=host
Daniel Lavoie
@daniellavoie
Aug 08 2016 22:22 UTC
Using a docker dynamic host port and with server.port=0 doesn't make sense. Docker needs to know which ports to map before your Spring Boot app start up. Why would you need to rely on host mode ?
ccit-spence
@ccit-spence
Aug 08 2016 22:29 UTC
Host mode allows for ip mapping based on the host. The setup is a hybrid with docker containers and physical or VM services. Docker containers run on cluster nodes.