Upgrade to Reactor 3.0 and start building against SI 5.0 snapshots
Closes gh-7301 See gh-7029pull/7306/head
parent
f7618cb421
commit
4486d2d209
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.reactor;
|
||||
|
||||
import reactor.Environment;
|
||||
import reactor.bus.EventBus;
|
||||
import reactor.spring.context.config.EnableReactor;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for Reactor.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ EnableReactor.class, Environment.class })
|
||||
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
|
||||
public class ReactorAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(EventBus.class)
|
||||
public EventBus eventBus(Environment environment) {
|
||||
return EventBus.create(environment);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnMissingBean(Environment.class)
|
||||
@EnableReactor
|
||||
protected static class ReactorConfiguration {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auto-configuration for Project Reactor.
|
||||
*/
|
||||
package org.springframework.boot.autoconfigure.reactor;
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.reactor;
|
||||
|
||||
import org.junit.Test;
|
||||
import reactor.bus.EventBus;
|
||||
import reactor.core.Dispatcher;
|
||||
import reactor.core.dispatch.MpscDispatcher;
|
||||
import reactor.core.dispatch.RingBufferDispatcher;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ReactorAutoConfiguration}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ReactorAutoConfigurationTests {
|
||||
|
||||
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
@Test
|
||||
public void eventBusIsAvailable() {
|
||||
this.context.register(ReactorAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
EventBus eventBus = this.context.getBean(EventBus.class);
|
||||
assertThat(eventBus.getDispatcher()).isInstanceOf(RingBufferDispatcher.class);
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customEventBus() {
|
||||
this.context.register(TestConfiguration.class, ReactorAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
EventBus eventBus = this.context.getBean(EventBus.class);
|
||||
assertThat(eventBus.getDispatcher()).isInstanceOf(MpscDispatcher.class);
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@Bean(destroyMethod = "shutdown")
|
||||
public Dispatcher dispatcher() {
|
||||
return new MpscDispatcher("test");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EventBus customEventBus() {
|
||||
return EventBus.create(dispatcher());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package org.test
|
||||
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
||||
@EnableReactor
|
||||
@Log
|
||||
class Runner implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
EventBus eventBus
|
||||
|
||||
private CountDownLatch latch = new CountDownLatch(1)
|
||||
|
||||
@PostConstruct
|
||||
void init() {
|
||||
log.info "Registering consumer"
|
||||
}
|
||||
|
||||
void run(String... args) {
|
||||
eventBus.notify("hello", Event.wrap("Phil"))
|
||||
log.info "Notified Phil"
|
||||
latch.await()
|
||||
}
|
||||
|
||||
@Bean
|
||||
CountDownLatch latch() {
|
||||
latch
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Consumer
|
||||
@Log
|
||||
class Greeter {
|
||||
|
||||
@Autowired
|
||||
EventBus eventBus
|
||||
|
||||
@Autowired
|
||||
private CountDownLatch latch
|
||||
|
||||
@Selector(value="hello")
|
||||
void receive(String data) {
|
||||
log.info "Hello ${data}"
|
||||
latch.countDown()
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.cli.compiler.autoconfigure;
|
||||
|
||||
import org.codehaus.groovy.ast.ClassNode;
|
||||
import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
||||
|
||||
import org.springframework.boot.cli.compiler.AstUtils;
|
||||
import org.springframework.boot.cli.compiler.CompilerAutoConfiguration;
|
||||
import org.springframework.boot.cli.compiler.DependencyCustomizer;
|
||||
|
||||
/**
|
||||
* {@link CompilerAutoConfiguration} for the Reactor.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class ReactorCompilerAutoConfiguration extends CompilerAutoConfiguration {
|
||||
|
||||
@Override
|
||||
public boolean matches(ClassNode classNode) {
|
||||
return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableReactor")
|
||||
|| AstUtils.hasAtLeastOneFieldOrMethod(classNode, "EventBus");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyDependencies(DependencyCustomizer dependencies) {
|
||||
dependencies.ifAnyMissingClasses("reactor.bus.EventBus")
|
||||
.add("reactor-spring-context", false).add("reactor-spring-core", false)
|
||||
.add("reactor-bus").add("reactor-stream");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyImports(ImportCustomizer imports) {
|
||||
imports.addImports("reactor.bus.Bus", "reactor.bus.Event", "reactor.bus.EventBus",
|
||||
"reactor.fn.Function", "reactor.fn.Functions", "reactor.fn.Predicate",
|
||||
"reactor.fn.Predicates", "reactor.fn.Supplier", "reactor.fn.Suppliers",
|
||||
"reactor.spring.context.annotation.Consumer",
|
||||
"reactor.spring.context.annotation.ReplyTo",
|
||||
"reactor.spring.context.annotation.Selector",
|
||||
"reactor.spring.context.annotation.SelectorType",
|
||||
"reactor.spring.context.config.EnableReactor")
|
||||
.addStarImports("reactor.bus.selector.Selectors")
|
||||
.addImport("ReactorEnvironment", "reactor.Environment");
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,14 @@
|
||||
@SpringBootTest(classes=ReactorApplication, webEnvironment=WebEnvironment.RANDOM_PORT)
|
||||
class RestTests {
|
||||
import org.springframework.jms.core.JmsTemplate
|
||||
|
||||
@SpringBootTest(classes=JmsExample)
|
||||
class JmsTests {
|
||||
|
||||
@Autowired
|
||||
EventBus eventBus
|
||||
JmsTemplate jmsTemplate
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
assertNotNull(eventBus)
|
||||
assertNotNull(jmsTemplate)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
@Grab("spring-boot-starter-artemis")
|
||||
@Grab("artemis-jms-server")
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
||||
@Log
|
||||
@Configuration
|
||||
@EnableJms
|
||||
class JmsExample implements CommandLineRunner {
|
||||
|
||||
private CountDownLatch latch = new CountDownLatch(1)
|
||||
|
||||
@Autowired
|
||||
JmsTemplate jmsTemplate
|
||||
|
||||
void run(String... args) {
|
||||
def messageCreator = { session ->
|
||||
session.createObjectMessage("Greetings from Spring Boot via Artemis")
|
||||
} as MessageCreator
|
||||
log.info "Sending JMS message..."
|
||||
jmsTemplate.send("spring-boot", messageCreator)
|
||||
log.info "Send JMS message, waiting..."
|
||||
latch.await()
|
||||
}
|
||||
|
||||
@JmsListener(destination = 'spring-boot')
|
||||
def receive(String message) {
|
||||
log.info "Received ${message}"
|
||||
latch.countDown()
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
@Configuration
|
||||
@EnableReactor
|
||||
class ReactorApplication {
|
||||
}
|
Loading…
Reference in New Issue