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

24th
Feb 2016
Niklas Herder
@herder
Feb 24 2016 08:47

Hi, I'm not sure if I'm misunderstanding something re @Header annotations.
This method gets called when posting a message to the RabbitMQ exchange, but the params aren't populated if I don't add them as headers.

    @ServiceActivator(inputChannel = BindingConfig.IndexRequest.reindex_request)
    public void processInput(
        @Header(value = "source", required = false, defaultValue = "root") String source,
        @Header(value = "stop", required = false, defaultValue = "false") Boolean stop,
        @Header(value = "after", required = false) Instant after,
        @Header(value = "before", required = false) Instant before
    ) {
        log.info("Got message: {}, {}, {}", stop, after, before);
        eventBus.notify(IndexEvent.class, Event.wrap(new IndexEvent(stop, source)));
    }

Am I misunderstanding something about the @Header annotation? Using spring-messaging 4.2.4.

Dave Syer
@dsyer
Feb 24 2016 09:02
You said "required=false" so I would expect nulls if the headers are not present
Is that what you mean?
Niklas Herder
@herder
Feb 24 2016 09:26
According to the javadoc for Header, required is implicitly set to false when I supply a default value. But if I remove the required=false, it throws an exception instead of using the default:
java.lang.IllegalArgumentException: required header not available: source
    at org.springframework.util.Assert.isTrue(Assert.java:68) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_74]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_74]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_74]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_74]
    at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:113) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:102) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:49) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:347) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.expression.spel.ast.Ternary.getValueInternal(Ternary.java:56) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.expression.spel.ast.MethodReference.getArguments(MethodReference.java:154) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
Dave Syer
@dsyer
Feb 24 2016 09:27
Ah, right. I guess the javadoc is wrong then?
Niklas Herder
@herder
Feb 24 2016 09:28
Yeah, there seems to be a mismatch there. But isn't it the behaviour which is wrong? Shouldn't the defaultValue kick in if the message doesn't contain that header?
Dave Syer
@dsyer
Feb 24 2016 09:31
It doesn't?
Niklas Herder
@herder
Feb 24 2016 09:45

Not as far as I can see:

Caused by: java.lang.IllegalArgumentException: required header not available: source

I'm posting from the Rabbit web console, with no headers at all.

I feel like I'm doing something wrong, but can't figure out what... :)
Dave Syer
@dsyer
Feb 24 2016 09:56
What's wrong with adding required=false?
Niklas Herder
@herder
Feb 24 2016 10:01
Then I get a null as param value
I'll try and set up a minimal project which reproduces the error later.
checketts
@checketts
Feb 24 2016 22:30
@dsyer We are running into performance problems with config server. I've traced it back to AbstractScmEnvironmentRepository#findOne being synchronized. I'm guessing that is a limitation with JGit. Is there any way around that limitation?
Dave Syer
@dsyer
Feb 24 2016 22:31
More instances?
Not much else anyone can do.
Cut down on your health checks
It m
It might be helpful to describe the problem in more detail
checketts
@checketts
Feb 24 2016 22:33
More instances is what I expected that solution to be. Thanks @dsyer
The problem is we have a legacy config server of our own design, that behaves as the nanny pushing configs out to services. (as opposed to services pulling their configs)
So I've retrofitted out legacy system to use config-server with Git as the source of truth, while we transition completely to a normal pull model with config-server
But to keep our push out the config to each service, our legacy service is calling the config-server on behalf of all the services and that refresh take 3+ minutes
Dave Syer
@dsyer
Feb 24 2016 22:36
I see. It's kind of artificial then.
I had an idea a while back about having multiple local working copies and synchronizing on those.
I don't think there anything stopping that
from happening
checketts
@checketts
Feb 24 2016 22:37
That is exactly what I would need. Since I know they will all be the same
Dave Syer
@dsyer
Feb 24 2016 22:38
You could probably do it by wrapping the existing repository in a wrapper that uses a pool
checketts
@checketts
Feb 24 2016 22:38
But wouldn't the call into the existing repository still hit the synchronized block?
Dave Syer
@dsyer
Feb 24 2016 22:39
yes, but if you have 10 of them you can service 10 requests concurrently
instead of 1
checketts
@checketts
Feb 24 2016 22:40
Oh right. My concurrency newb is showing. synchronized blocks on the instance
not on a single static per jvm
Dave Syer
@dsyer
Feb 24 2016 22:40
Indeed
checketts
@checketts
Feb 24 2016 22:40
Thanks! That gives me a very workable solution.
Excellent. Looks like I'll just create my own PoolingEnvironmentRepository that implements EnvironmentRepository
Dave Syer
@dsyer
Feb 24 2016 22:45
PR welcome
checketts
@checketts
Feb 24 2016 22:51
Why is there any synchronization at all? I can't see anything that jumps out as not being thread safe
I'm trying to reason through how I can be certain that I'm not breaking something
Spencer Gibb
@spencergibb
Feb 24 2016 23:44
@checketts there are some file locking issues on some operating systems (windows :frowning:)