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

13th
Jan 2017
Ali Shahbour
@shahbour
Jan 13 2017 08:20
i am strugling to find the best architecture for an UI with microservices behind a gateway . should i put the UI also behind the gateway and call it like /ui/… or i should do a proxy and load balance on its own ?
Marcos Barbero
@marcosbarbero
Jan 13 2017 08:41
IMHO it's easier to deal with UI in a different place than the microservices gateway. You can make it under a gateway but make a new one just for UI or use the approach you mentioned with a proxy and load balancer
Ali Shahbour
@shahbour
Jan 13 2017 08:45
the reason i thought of putting it under the gateway is to have load balancing and be able to do update without end user interruption
Marcos Barbero
@marcosbarbero
Jan 13 2017 08:48
I knew it! hehe I did the same before
But after a while you'll notice that having the microservices and UI under the same gateway isn't a good idea because you start to have a lot of different things working in the same place.
So my approach at that time was to create two gateways. The first one was handling only the microservices and the second one was handling just the UI
You know what I mean?
Ali Shahbour
@shahbour
Jan 13 2017 08:50
Yes , thanks for sharing the experiense .
did u face any problem due to CORS
Marcos Barbero
@marcosbarbero
Jan 13 2017 08:53

You can have the both gateways working under the same domain, something like:
1 - api.companiesdomain.com
2 - ui.companiesdomain.com

This way you won't have any CORS issue

Ali Shahbour
@shahbour
Jan 13 2017 08:54
nice , let me try that
Casey Link
@Ramblurr
Jan 13 2017 10:08
When I run a spring cloud task project, the task executes, but the process doesn't exit
Do I have to manually call System.exit?
Ali Shahbour
@shahbour
Jan 13 2017 10:20
it should exit by itself and save the exit code in task database
Casey Link
@Ramblurr
Jan 13 2017 10:20
I do see that the exit code is saved (0) and the end_time is not null in the task_execution table
Ali Shahbour
@shahbour
Jan 13 2017 10:21
if you run the application manually does it end ?
Casey Link
@Ramblurr
Jan 13 2017 10:21
the last thing logged to the console is c.c.task.MyTaskApplication : Started MyTaskApplication in 30.205 seconds (JVM running for 31.058)
Ali Shahbour
@shahbour
Jan 13 2017 10:21
does it have web ?
if you run MyTaskApplication as java -jar does it start and end ?
Casey Link
@Ramblurr
Jan 13 2017 10:22
I have `spring.main.web-environment= false``
Ali Shahbour
@shahbour
Jan 13 2017 10:22
so it ends ?
Casey Link
@Ramblurr
Jan 13 2017 10:24
it doesnt exit no matter if i run the jar directly or using gradle bootRun
my boot starters are
Ali Shahbour
@shahbour
Jan 13 2017 10:27
so the problem is not related spring boot task
Casey Link
@Ramblurr
Jan 13 2017 10:28
    compile('org.springframework.boot:spring-boot-starter-batch')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.cloud:spring-cloud-starter-config')
    compile('org.springframework.cloud:spring-cloud-task-starter')
    compile('org.springframework.retry:spring-retry')
Ali Shahbour
@shahbour
Jan 13 2017 10:28
it is related to your jar , it has to exit to be a task
can u give more details about the log
Casey Link
@Ramblurr
Jan 13 2017 10:29
yup one moment
Ali Shahbour
@shahbour
Jan 13 2017 10:46
mm couldn’t tell what it is waiting for !
Casey Link
@Ramblurr
Jan 13 2017 11:06
I'm creating several beans in the application class
along side the CommandLineRunner bean
but they are just injected into the CommandLineRunner and they are normal beans, nothing special
Ali Shahbour
@shahbour
Jan 13 2017 11:08
i see you have reference to spring batch
do u have any job declared , i did not see any in the log
Casey Link
@Ramblurr
Jan 13 2017 11:08
nope i have it as a dep, but I haven't used it yet.
I've just gone ahead and removed unused boot starters from my build.gradle
batch and cloud config starters, and spring-retry
but no luck getting it to exit
Patrick Cornelißen
@pcornelissen
Jan 13 2017 11:14
is it running in a container? I ran into startup issues when the app sucked the /dev/random of my docker process dry ;-) I had to mount the hosts dev/urandom into it and the startup issue was gone
Casey Link
@Ramblurr
Jan 13 2017 11:23
Actually I believe the issue is an ExecutorService that was created as part of my task's job is preventing the JVM from exiting
yup that was it!
Casey Link
@Ramblurr
Jan 13 2017 11:45
thanks for the support @shahbour
Ali Shahbour
@shahbour
Jan 13 2017 11:46
great you found it
Casey Link
@Ramblurr
Jan 13 2017 12:15
@shahbour Can spring cloud task and spring-data-jpa be used together:
I'm having an issue where my spring data jpa repositories' save() method isn't triggering an INSERT statement and I'm wondering if the JPA/JDBC stuff from cloud-task is conflicting with it
Dave Syer
@dsyer
Jan 13 2017 12:34
Task doesn't have any JPA features
What makes you say there is no INSERT?
Maybe there's a transaction that hasn't finished yet?
Casey Link
@Ramblurr
Jan 13 2017 12:37
Hm, it is definitely some sort of conflict with spring-cloud-task. If I remove the @EnableTask annotation and let the CommandLineRunner run with normal spring boot, I can save entities just fine. When the @EnableTask is present however, the inserts never take place.
By "no insert" I mean the org.hibernate.SQL isn't logging an insert statement
I see the org.hibernate.SQL : select nextval ('public.hibernate_sequence') query when it attempts to locate the next ID for a newly created entity
but there is no followup insert statement. there are also no errors.
when I remove the @EnableTask annotation I see a org.hibernate.SQL : insert .... immediately following the select nextval
it looks like spring-cloud-task-core depends on spring-batch
Casey Link
@Ramblurr
Jan 13 2017 12:51
Ok, more clues.
a diff between the auto-configuration report of the two case (one with @EnableTask and one without, broken and working respectively)
reveals this:
81,83d80
<    JpaBaseConfiguration#transactionManager matched:
<       - @ConditionalOnMissingBean (types: org.springframework.transaction.PlatformTransactionManager; SearchStrategy: all) did not find any beans (OnBeanCondition)
<
405a403,406
>    JpaBaseConfiguration#transactionManager:
>       Did not match:
>          - @ConditionalOnMissingBean (types: org.springframework.transaction.PlatformTransactionManager; SearchStrategy: all) found bean 'transactionManager' (OnBeanCondition)
so when spring cloud task is enabled, the spring-data-jpa JpaBaseConfiguration#transactionManager bean is NOT created because some other bean with the name transactionManager exists
Where is that transactionManager bean coming from?
Casey Link
@Ramblurr
Jan 13 2017 12:58
It's coming from the SimpleTaskConfiguration thats loaded with @EnableTask
Ali Shahbour
@shahbour
Jan 13 2017 12:59
you need the transactionManager to manage your transactions . seems you are not commiting your save . How are you doing the insert ?
Casey Link
@Ramblurr
Jan 13 2017 12:59
@Transactional
@Service
public class StoreService
{

    @Autowired OrganizationRepository organizationRepository;

    Organization save(Organization organization)
    {
        return organizationRepository.save(organization);
    }
}
yup, I realize I need the transactionManager, but I think the transactionManager bean from cloud-task is causing issues with data-jpa
Dave Syer
@dsyer
Jan 13 2017 13:01
Maybe it's not a JpaTransactionManager
Can you push a simple sample to github?
Casey Link
@Ramblurr
Jan 13 2017 13:01
sure
Dave Syer
@dsyer
Jan 13 2017 13:14
Nevermind. I can see it's not going to be a JpaTransactionManager
I guess you maybe can work around it by creating your own
Casey Link
@Ramblurr
Jan 13 2017 13:19
Here's a sample test case any how: https://github.com/Ramblurr/spring-data-task-conflict
gah ok, adding this to the config seems to fix it..
    @Autowired
    EntityManagerFactory entityManagerFactory;

    @Bean
    public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory)
    {
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(entityManagerFactory);

        return transactionManager;
    }
what a rabbit hole heh
Casey Link
@Ramblurr
Jan 13 2017 13:24
Should I open a ticket about this? At the least a note should be added to the documentation about this I suspect
Dave Syer
@dsyer
Jan 13 2017 13:26
I would, yes.
Seems like a bug to me at least
Casey Link
@Ramblurr
Jan 13 2017 13:31
what's the issue exactly? data-jpa expects a JpaTransactionManager but cloud-task provides another type?
Dave Syer
@dsyer
Jan 13 2017 13:34
Yes
Casey Link
@Ramblurr
Jan 13 2017 13:34
spring-cloud/spring-cloud-task#270
Casey Link
@Ramblurr
Jan 13 2017 14:45
@dsyer do you know of a code example for spring-batch that involves multiple steps in once job
where the output of a step is used as the input to the next step
Ali Shahbour
@shahbour
Jan 13 2017 14:46
what do u mean by output of a step input to another ?
what is the output ?
Casey Link
@Ramblurr
Jan 13 2017 14:48
Ah, I see. the steps don't have any output as far as spring-batch is concerned. I can accomplish what I want with step 1 writing into a db, then step 2 reading from that db
Ali Shahbour
@shahbour
Jan 13 2017 14:49
this is one way , if you always have to do step1 and step2 in case of restart then you can save the output in a bean with scope JOB
Avanish Pathak
@5punk
Jan 13 2017 21:23
Hi guys, I am trying to move our config over to spring cloud. But I want to transition slowly, is there a way I can use my service-context.xml and also my spring config client?
Half and half?
cause @Value("test.value") looks inside my service-context.xml only.
How do I tell @Value() to access my spring cloud config as well as my service-context.xml?
Dave Syer
@dsyer
Jan 13 2017 21:34
Anything that works with @Value works with Spring Cloud Config
It's just another PropertySource