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

9th
Aug 2016
Ryan Baxter
@ryanjbaxter
Aug 09 2016 00:34
couple of more tweaks I want to make tomorrow
Mike Liu
@mikexliu
Aug 09 2016 02:03
Hi, does anyone know why @EnableFeignClients does not register its LoadBalancers into ClientFactory.java?
Spencer Gibb
@spencergibb
Aug 09 2016 02:59
@mikexliu which ClientFactory?
Mike Liu
@mikexliu
Aug 09 2016 05:53
@spencergibb Referring to https://github.com/Netflix/ribbon/blob/master/ribbon-loadbalancer/src/main/java/com/netflix/client/ClientFactory.java . I'm not sure if this is the right channel for the question either.
Daniel Lavoie
@daniellavoie
Aug 09 2016 06:20
@ccit-spence Not quite sure you rely on need to rely on host mode. Just revert to a classic port mapping mode. Hardcode your port with server.port=8080and expose that port with -P. Docker containers assure you that ports won't conflict.
ccit-spence
@ccit-spence
Aug 09 2016 07:19
@daniellavoie Was not sure how Eureka / where Eureka pulls its port information. Container level or Host level.
Daniel Lavoie
@daniellavoie
Aug 09 2016 07:44
@ccit-spence Eureka relies on the information provided by the client during registration. If your Eureka instance is running inside a container, you'll have to link that container with the one of your Spring Cloud app so ports gets automatically mapped internally. For exemple, configure server.port=8080 and link your Eureka container to your app container. I think you should read a little more about Docker networking. You'll see that linked containers can see each others without looping back to your host on dynamic ports.
Dreampie
@Dreampie
Aug 09 2016 07:44
hystrix.plugin.HystrixConcurrencyStrategy.implementation how can config more than 1 instance.
@spencergibb
ccit-spence
@ccit-spence
Aug 09 2016 07:45
Eureka is not running within Docker in my case
Marcin Grzejszczak
@marcingrzejszczak
Aug 09 2016 07:49
@Dreampie if you're asking about registering more than one instance of HystrixConcurrencyStrategy then as far as I know it's not possible
Daniel Lavoie
@daniellavoie
Aug 09 2016 07:50
@ccit-spence In this case you won't be able to use dynamic port. Docker as no means to find out which port will be used by your Spring Boot app once the container is started.
ccit-spence
@ccit-spence
Aug 09 2016 07:51
@daniellavoie yep, that is what I am hitting
wasn’t sure if anyone worked out a way around it
Daniel Lavoie
@daniellavoie
Aug 09 2016 07:53
@marcingrzejszczak @Dreampie Indeed, for this spring-cloud/spring-cloud-netflix#1093, I had to implement an extension mechanism so HystrixConcurrencyStrategy from Sleuth won't be overwritten.
Dreampie
@Dreampie
Aug 09 2016 07:53
@marcingrzejszczak
some thing use thread local : private static final ThreadLocal<Session> sessionTL = new ThreadLocal<Session>();, code like this?if two object need threadlocal,how to write?
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);
      }
    }
  }

  private static class SessionConcurrencyStrategy extends HystrixConcurrencyStrategy {
    public <T> Callable<T> wrapCallable(Callable<T> callable) {
      return new SessionCallable<T>(callable);
    }
  }
Marcin Grzejszczak
@marcingrzejszczak
Aug 09 2016 07:54
@daniellavoie yeah it's a problem of ordering. In Sleuth as far as I remember we respect that another strategy could have been registered already
@Dreampie I'm sorry but I don't understand the question
can you elaborate on this a little bit more
Daniel Lavoie
@daniellavoie
Aug 09 2016 07:55
@marcingrzejszczak Indeed, I got inspired by your Sleuth Snippet for the auto configuration mecanism I implemented on the PR.
Marcin Grzejszczak
@marcingrzejszczak
Aug 09 2016 07:55
:+1: nice to hear :)
Dreampie
@Dreampie
Aug 09 2016 07:56
In my code, requestMapping add @HystrixCommand annotation,but ThreadLocal always return null, so I want resolve this .
Marcin Grzejszczak
@marcingrzejszczak
Aug 09 2016 07:57
ah very good
check out Sleuth's concurrency strategy
Daniel Lavoie
@daniellavoie
Aug 09 2016 07:57

@Dreampie @marcingrzejszczak

Pretty much like this...

@Configuration
@Conditional(HystrixSecurityCondition.class)
@ConditionalOnClass({ Hystrix.class, SecurityContext.class })
public class HystrixSecurityAutoConfiguration {
    @Autowired(required = false)
    private HystrixConcurrencyStrategy existingConcurrencyStrategy;

    @PostConstruct
    public void init() {
        // Keeps references of existing Hystrix plugins.
        HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance()
                .getEventNotifier();
        HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
                .getMetricsPublisher();
        HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
                .getPropertiesStrategy();
        HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance()
                .getCommandExecutionHook();

        HystrixPlugins.reset();

        // Registers existing plugins excepts the Concurrent Strategy plugin.
        HystrixPlugins.getInstance().registerConcurrencyStrategy(
                new SecurityContextConcurrencyStrategy(existingConcurrencyStrategy));
        HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
        HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
        HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
        HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
    }
Marcin Grzejszczak
@marcingrzejszczak
Aug 09 2016 07:57
yup - looks nice :)
hmm but HystrixConcurrencyStrategy is a bean ?
oh yeah it is
I've forgotten :D
Dreampie
@Dreampie
Aug 09 2016 07:59
I copy this code ,and add hystrix.plugin.HystrixConcurrencyStrategy.implementation in application.ml, it’s ok?
Marcin Grzejszczak
@marcingrzejszczak
Aug 09 2016 07:59
no - as you can see it's registered programatically
read @daniellavoie 's code from the snippet
Dreampie
@Dreampie
Aug 09 2016 08:02
ok, SecurityContextConcurrencyStrategy where can found
Daniel Lavoie
@daniellavoie
Aug 09 2016 08:03
Checkout my pull request. I am pretty sure it will fix your problem. Until it is merged, you can inspire yourself of what I did and reimplement the auto configuration in your App.
Marcin Grzejszczak
@marcingrzejszczak
Aug 09 2016 08:03
you can also check the Sleuth's code - it's doing similar stuff
Dreampie
@Dreampie
Aug 09 2016 08:08
I see, why not add in spring cloud netflix?
Marcin Grzejszczak
@marcingrzejszczak
Aug 09 2016 08:09
add what?
Dreampie
@Dreampie
Aug 09 2016 08:12
generic implemention of HystrixConcurrencyAutoConfiguration
Daniel Lavoie
@daniellavoie
Aug 09 2016 08:14
That's the goal of my PR, should be integrated for 1.2.0.M1
Marcin Grzejszczak
@marcingrzejszczak
Aug 09 2016 08:16
:+1:
Dreampie
@Dreampie
Aug 09 2016 08:16
:+1:
finneym
@finneym
Aug 09 2016 09:15
@marcosbarbero Thanks for getting back, that link is perfect :) Thank you!
Marcin Grzejszczak
@marcingrzejszczak
Aug 09 2016 09:16
it's awesome to have such a great community like all of you people :D
Dreampie
@Dreampie
Aug 09 2016 09:22
@daniellavoie If I use your PR,I must add security,but I don’t use it,I only want normal Threadlocal work fine with @HystrixCommand ,this code how to change?
public <T> Callable<T> wrapCallable(Callable<T> callable) {
        return existingConcurrencyStrategy != null
                ? existingConcurrencyStrategy
                .wrapCallable(new DelegatingSecurityContextCallable<T>(callable))
                : super.wrapCallable(new DelegatingSecurityContextCallable<T>(callable));
    }
Dreampie
@Dreampie
Aug 09 2016 09:31
remove DelegatingSecurityContextCallable?
Marcos Barbero
@marcosbarbero
Aug 09 2016 11:20
@finneym you’re welcome!
Greg Nass
@gnass
Aug 09 2016 20:10
is it possible to disable an annotation depending on how the app is being deployed? trying to deploy the same application to pcf and mesos using @EnableDiscoveryClient for pcf w/ eureka and minuteman for mesos so i'd only want the app to attempt to register with eureka when deployed to pcf
is setting spring.cloud.discovery.enabled=false the correct approach?
Marcos Barbero
@marcosbarbero
Aug 09 2016 20:16
You’re in the right way, make two profiles to handle this property
Josh Fix
@joshfix
Aug 09 2016 20:21
pcf also automatically runs your spring apps with the cloud profile
so you can annotate classes/methods with @Profile("!cloud") if you want it to run outside of pcf, or @Profile("cloud") for running inside pcf
Daniel Lavoie
@daniellavoie
Aug 09 2016 20:38
Environment variables are also available as spring properties
Josh Fix
@joshfix
Aug 09 2016 21:24
@gnass it's a very interesting topic... We were considering building our own starters for different platforms and controlling what gets loaded through maven profiles. I'm glad others are starting to discuss how to handle this as well.
Greg Nass
@gnass
Aug 09 2016 21:42
does the @EnableDiscoveryClient annotation provided by spring cloud override the property set in bootstrap.yml? i tried creating a profile and setting it to false, but its still trying to register as if the annotation is winning
Josh Fix
@joshfix
Aug 09 2016 21:44
I'm not sure. Maybe provide a separate class annotated with @Configuration, @Profile, and @EnableDiscoveryClient
then that configuration class should only get loaded and enable discovery if the profile matches