Merge remote-tracking branch 'upstream/master' into tutorials/binaryTreeJava
This commit is contained in:
commit
7775a9bbe2
|
@ -14,7 +14,7 @@
|
|||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
<version>2.0.0.M7</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
|
@ -87,14 +87,6 @@
|
|||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
|
@ -106,14 +98,6 @@
|
|||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
## Relevant articles:
|
||||
|
||||
- [Intro to Dubbo](http://www.baeldung.com/dubbo-intro)
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dubbo</artifactId>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<dubbo.version>2.5.7</dubbo.version>
|
||||
<zookeeper.version>3.4.11</zookeeper.version>
|
||||
<zkclient.version>0.10</zkclient.version>
|
||||
<surefire.version>2.19.1</surefire.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
<version>${dubbo.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
<version>${zookeeper.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.101tec</groupId>
|
||||
<artifactId>zkclient</artifactId>
|
||||
<version>${zkclient.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.version}</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,210 @@
|
|||
/*
|
||||
* Copyright 1999-2011 Alibaba Group.
|
||||
*
|
||||
* 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 com.alibaba.dubbo.registry.simple;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
import com.alibaba.dubbo.common.utils.ConcurrentHashSet;
|
||||
import com.alibaba.dubbo.common.utils.NetUtils;
|
||||
import com.alibaba.dubbo.common.utils.UrlUtils;
|
||||
import com.alibaba.dubbo.registry.NotifyListener;
|
||||
import com.alibaba.dubbo.registry.RegistryService;
|
||||
import com.alibaba.dubbo.registry.support.AbstractRegistry;
|
||||
import com.alibaba.dubbo.rpc.RpcContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* SimpleRegistryService
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class SimpleRegistryService extends AbstractRegistry {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(SimpleRegistryService.class);
|
||||
private final ConcurrentMap<String, Set<URL>> remoteRegistered = new ConcurrentHashMap<String, Set<URL>>();
|
||||
private final ConcurrentMap<String, ConcurrentMap<URL, Set<NotifyListener>>> remoteSubscribed = new ConcurrentHashMap<String, ConcurrentMap<URL, Set<NotifyListener>>>();
|
||||
|
||||
public SimpleRegistryService() {
|
||||
super(new URL("dubbo", NetUtils.getLocalHost(), 0, RegistryService.class.getName(), "file", "N/A"));
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<URL> lookup(URL url) {
|
||||
List<URL> urls = new ArrayList<URL>();
|
||||
for (URL u : getRegistered()) {
|
||||
if (UrlUtils.isMatch(url, u)) {
|
||||
urls.add(u);
|
||||
}
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
|
||||
public void register(URL url) {
|
||||
String client = RpcContext.getContext().getRemoteAddressString();
|
||||
Set<URL> urls = remoteRegistered.get(client);
|
||||
if (urls == null) {
|
||||
remoteRegistered.putIfAbsent(client, new ConcurrentHashSet<URL>());
|
||||
urls = remoteRegistered.get(client);
|
||||
}
|
||||
urls.add(url);
|
||||
super.register(url);
|
||||
registered(url);
|
||||
}
|
||||
|
||||
public void unregister(URL url) {
|
||||
String client = RpcContext.getContext().getRemoteAddressString();
|
||||
Set<URL> urls = remoteRegistered.get(client);
|
||||
if (urls != null && urls.size() > 0) {
|
||||
urls.remove(url);
|
||||
}
|
||||
super.unregister(url);
|
||||
unregistered(url);
|
||||
}
|
||||
|
||||
public void subscribe(URL url, NotifyListener listener) {
|
||||
if (getUrl().getPort() == 0) {
|
||||
URL registryUrl = RpcContext.getContext().getUrl();
|
||||
if (registryUrl != null && registryUrl.getPort() > 0
|
||||
&& RegistryService.class.getName().equals(registryUrl.getPath())) {
|
||||
super.setUrl(registryUrl);
|
||||
super.register(registryUrl);
|
||||
}
|
||||
}
|
||||
String client = RpcContext.getContext().getRemoteAddressString();
|
||||
ConcurrentMap<URL, Set<NotifyListener>> clientListeners = remoteSubscribed.get(client);
|
||||
if (clientListeners == null) {
|
||||
remoteSubscribed.putIfAbsent(client, new ConcurrentHashMap<URL, Set<NotifyListener>>());
|
||||
clientListeners = remoteSubscribed.get(client);
|
||||
}
|
||||
Set<NotifyListener> listeners = clientListeners.get(url);
|
||||
if (listeners == null) {
|
||||
clientListeners.putIfAbsent(url, new ConcurrentHashSet<NotifyListener>());
|
||||
listeners = clientListeners.get(url);
|
||||
}
|
||||
listeners.add(listener);
|
||||
super.subscribe(url, listener);
|
||||
subscribed(url, listener);
|
||||
}
|
||||
|
||||
public void unsubscribe(URL url, NotifyListener listener) {
|
||||
if (!Constants.ANY_VALUE.equals(url.getServiceInterface())
|
||||
&& url.getParameter(Constants.REGISTER_KEY, true)) {
|
||||
unregister(url);
|
||||
}
|
||||
String client = RpcContext.getContext().getRemoteAddressString();
|
||||
Map<URL, Set<NotifyListener>> clientListeners = remoteSubscribed.get(client);
|
||||
if (clientListeners != null && clientListeners.size() > 0) {
|
||||
Set<NotifyListener> listeners = clientListeners.get(url);
|
||||
if (listeners != null && listeners.size() > 0) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void registered(URL url) {
|
||||
for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
|
||||
URL key = entry.getKey();
|
||||
if (UrlUtils.isMatch(key, url)) {
|
||||
List<URL> list = lookup(key);
|
||||
for (NotifyListener listener : entry.getValue()) {
|
||||
listener.notify(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void unregistered(URL url) {
|
||||
for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
|
||||
URL key = entry.getKey();
|
||||
if (UrlUtils.isMatch(key, url)) {
|
||||
List<URL> list = lookup(key);
|
||||
for (NotifyListener listener : entry.getValue()) {
|
||||
listener.notify(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void subscribed(final URL url, final NotifyListener listener) {
|
||||
if (Constants.ANY_VALUE.equals(url.getServiceInterface())) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
Map<String, List<URL>> map = new HashMap<String, List<URL>>();
|
||||
for (URL u : getRegistered()) {
|
||||
if (UrlUtils.isMatch(url, u)) {
|
||||
String service = u.getServiceInterface();
|
||||
List<URL> list = map.get(service);
|
||||
if (list == null) {
|
||||
list = new ArrayList<URL>();
|
||||
map.put(service, list);
|
||||
}
|
||||
list.add(u);
|
||||
}
|
||||
}
|
||||
for (List<URL> list : map.values()) {
|
||||
try {
|
||||
listener.notify(list);
|
||||
} catch (Throwable e) {
|
||||
logger.warn("Discard to notify " + url.getServiceKey() + " to listener " + listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, "DubboMonitorNotifier").start();
|
||||
} else {
|
||||
List<URL> list = lookup(url);
|
||||
try {
|
||||
listener.notify(list);
|
||||
} catch (Throwable e) {
|
||||
logger.warn("Discard to notify " + url.getServiceKey() + " to listener " + listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
String client = RpcContext.getContext().getRemoteAddressString();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Disconnected " + client);
|
||||
}
|
||||
Set<URL> urls = remoteRegistered.get(client);
|
||||
if (urls != null && urls.size() > 0) {
|
||||
for (URL url : urls) {
|
||||
unregister(url);
|
||||
}
|
||||
}
|
||||
Map<URL, Set<NotifyListener>> listeners = remoteSubscribed.get(client);
|
||||
if (listeners != null && listeners.size() > 0) {
|
||||
for (Map.Entry<URL, Set<NotifyListener>> entry : listeners.entrySet()) {
|
||||
URL url = entry.getKey();
|
||||
for (NotifyListener listener : entry.getValue()) {
|
||||
unsubscribe(url, listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.baeldung.dubbo.remote;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class GreetingsFailoverServiceImpl implements GreetingsService {
|
||||
|
||||
@Override
|
||||
public String sayHi(String name) {
|
||||
System.out.println("failover implementation");
|
||||
return "hi, failover " + name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.dubbo.remote;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public interface GreetingsService {
|
||||
|
||||
String sayHi(String name);
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.baeldung.dubbo.remote;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class GreetingsServiceImpl implements GreetingsService {
|
||||
|
||||
@Override
|
||||
public String sayHi(String name) {
|
||||
System.out.println("default implementation");
|
||||
return "hi, " + name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.dubbo.remote;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class GreetingsServiceSpecialImpl implements GreetingsService {
|
||||
|
||||
@Override
|
||||
public String sayHi(String name) {
|
||||
try {
|
||||
System.out.println("specially called");
|
||||
SECONDS.sleep(5);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return "hi, " + name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.baeldung.dubbo;
|
||||
|
||||
import com.alibaba.dubbo.config.ApplicationConfig;
|
||||
import com.alibaba.dubbo.config.ReferenceConfig;
|
||||
import com.alibaba.dubbo.config.RegistryConfig;
|
||||
import com.alibaba.dubbo.config.ServiceConfig;
|
||||
import com.baeldung.dubbo.remote.GreetingsService;
|
||||
import com.baeldung.dubbo.remote.GreetingsServiceImpl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class APIConfigurationLiveTest {
|
||||
|
||||
@Before
|
||||
public void initProvider() {
|
||||
ApplicationConfig application = new ApplicationConfig();
|
||||
application.setName("demo-provider");
|
||||
application.setVersion("1.0");
|
||||
|
||||
RegistryConfig registryConfig = new RegistryConfig();
|
||||
registryConfig.setAddress("multicast://224.1.1.1:9090");
|
||||
|
||||
ServiceConfig<GreetingsService> service = new ServiceConfig<>();
|
||||
service.setApplication(application);
|
||||
service.setRegistry(registryConfig);
|
||||
service.setInterface(GreetingsService.class);
|
||||
service.setRef(new GreetingsServiceImpl());
|
||||
|
||||
service.export();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProviderConsumer_whenSayHi_thenGotResponse() {
|
||||
ApplicationConfig application = new ApplicationConfig();
|
||||
application.setName("demo-consumer");
|
||||
application.setVersion("1.0");
|
||||
|
||||
RegistryConfig registryConfig = new RegistryConfig();
|
||||
registryConfig.setAddress("multicast://224.1.1.1:9090");
|
||||
|
||||
ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
|
||||
reference.setApplication(application);
|
||||
reference.setRegistry(registryConfig);
|
||||
reference.setInterface(GreetingsService.class);
|
||||
|
||||
GreetingsService greetingsService = reference.get();
|
||||
String hiMessage = greetingsService.sayHi("baeldung");
|
||||
|
||||
assertEquals("hi, baeldung", hiMessage);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.baeldung.dubbo;
|
||||
|
||||
import com.baeldung.dubbo.remote.GreetingsService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class ClusterDynamicLoadBalanceLiveTest {
|
||||
|
||||
private ExecutorService executorService;
|
||||
|
||||
@Before
|
||||
public void initRemote() {
|
||||
executorService = Executors.newFixedThreadPool(2);
|
||||
executorService.submit(() -> {
|
||||
ClassPathXmlApplicationContext remoteContext = new ClassPathXmlApplicationContext("cluster/provider-app-default.xml");
|
||||
remoteContext.start();
|
||||
});
|
||||
executorService.submit(() -> {
|
||||
SECONDS.sleep(2);
|
||||
ClassPathXmlApplicationContext backupRemoteContext = new ClassPathXmlApplicationContext("cluster/provider-app-special.xml");
|
||||
backupRemoteContext.start();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProviderCluster_whenConsumerSaysHi_thenResponseBalanced() throws InterruptedException {
|
||||
ClassPathXmlApplicationContext localContext = new ClassPathXmlApplicationContext("cluster/consumer-app-lb.xml");
|
||||
localContext.start();
|
||||
GreetingsService greetingsService = (GreetingsService) localContext.getBean("greetingsService");
|
||||
List<Long> elapseList = new ArrayList<>(6);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
long current = System.currentTimeMillis();
|
||||
String hiMessage = greetingsService.sayHi("baeldung");
|
||||
assertNotNull(hiMessage);
|
||||
elapseList.add(System.currentTimeMillis() - current);
|
||||
SECONDS.sleep(1);
|
||||
}
|
||||
|
||||
OptionalDouble avgElapse = elapseList
|
||||
.stream()
|
||||
.mapToLong(e -> e)
|
||||
.average();
|
||||
assertTrue(avgElapse.isPresent());
|
||||
assertTrue(avgElapse.getAsDouble() > 1666.0);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
executorService.shutdown();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.baeldung.dubbo;
|
||||
|
||||
import com.baeldung.dubbo.remote.GreetingsService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class ClusterFailoverLiveTest {
|
||||
|
||||
private ExecutorService executorService;
|
||||
|
||||
@Before
|
||||
public void initRemote() {
|
||||
executorService = Executors.newFixedThreadPool(2);
|
||||
executorService.submit(() -> {
|
||||
ClassPathXmlApplicationContext backupRemoteContext = new ClassPathXmlApplicationContext("cluster/provider-app-special.xml");
|
||||
backupRemoteContext.start();
|
||||
});
|
||||
executorService.submit(() -> {
|
||||
ClassPathXmlApplicationContext remoteContext = new ClassPathXmlApplicationContext("cluster/provider-app-failover.xml");
|
||||
remoteContext.start();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProviderCluster_whenConsumerSaysHi_thenGotFailoverResponse() {
|
||||
ClassPathXmlApplicationContext localContext = new ClassPathXmlApplicationContext("cluster/consumer-app-failtest.xml");
|
||||
localContext.start();
|
||||
GreetingsService greetingsService = (GreetingsService) localContext.getBean("greetingsService");
|
||||
String hiMessage = greetingsService.sayHi("baeldung");
|
||||
|
||||
assertNotNull(hiMessage);
|
||||
assertEquals("hi, failover baeldung", hiMessage);
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
executorService.shutdown();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.baeldung.dubbo;
|
||||
|
||||
import com.baeldung.dubbo.remote.GreetingsService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class ClusterFailsafeLiveTest {
|
||||
|
||||
private ExecutorService executorService;
|
||||
|
||||
@Before
|
||||
public void initRemote() {
|
||||
executorService = Executors.newFixedThreadPool(1);
|
||||
executorService.submit(() -> {
|
||||
ClassPathXmlApplicationContext remoteContext = new ClassPathXmlApplicationContext("cluster/provider-app-special-failsafe.xml");
|
||||
remoteContext.start();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProviderCluster_whenConsumerSaysHi_thenGotFailsafeResponse() {
|
||||
ClassPathXmlApplicationContext localContext = new ClassPathXmlApplicationContext("cluster/consumer-app-failtest.xml");
|
||||
localContext.start();
|
||||
GreetingsService greetingsService = (GreetingsService) localContext.getBean("greetingsService");
|
||||
String hiMessage = greetingsService.sayHi("baeldung");
|
||||
|
||||
assertNull(hiMessage);
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
executorService.shutdown();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.baeldung.dubbo;
|
||||
|
||||
import com.baeldung.dubbo.remote.GreetingsService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class ClusterLoadBalanceLiveTest {
|
||||
|
||||
private ExecutorService executorService;
|
||||
|
||||
@Before
|
||||
public void initRemote() {
|
||||
executorService = Executors.newFixedThreadPool(2);
|
||||
executorService.submit(() -> {
|
||||
ClassPathXmlApplicationContext remoteContext = new ClassPathXmlApplicationContext("cluster/provider-app-default.xml");
|
||||
remoteContext.start();
|
||||
});
|
||||
executorService.submit(() -> {
|
||||
ClassPathXmlApplicationContext backupRemoteContext = new ClassPathXmlApplicationContext("cluster/provider-app-special.xml");
|
||||
backupRemoteContext.start();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProviderCluster_whenConsumerSaysHi_thenResponseBalanced() {
|
||||
ClassPathXmlApplicationContext localContext = new ClassPathXmlApplicationContext("cluster/consumer-app-lb.xml");
|
||||
localContext.start();
|
||||
GreetingsService greetingsService = (GreetingsService) localContext.getBean("greetingsService");
|
||||
List<Long> elapseList = new ArrayList<>(6);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
long current = System.currentTimeMillis();
|
||||
String hiMessage = greetingsService.sayHi("baeldung");
|
||||
assertNotNull(hiMessage);
|
||||
elapseList.add(System.currentTimeMillis() - current);
|
||||
}
|
||||
|
||||
OptionalDouble avgElapse = elapseList
|
||||
.stream()
|
||||
.mapToLong(e -> e)
|
||||
.average();
|
||||
assertTrue(avgElapse.isPresent());
|
||||
System.out.println(avgElapse.getAsDouble());
|
||||
assertTrue(avgElapse.getAsDouble() > 2500.0);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
executorService.shutdown();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.baeldung.dubbo;
|
||||
|
||||
import com.baeldung.dubbo.remote.GreetingsService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class MulticastRegistryLiveTest {
|
||||
|
||||
private ClassPathXmlApplicationContext remoteContext;
|
||||
|
||||
@Before
|
||||
public void initRemote() {
|
||||
remoteContext = new ClassPathXmlApplicationContext("multicast/provider-app.xml");
|
||||
remoteContext.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProvider_whenConsumerSaysHi_thenGotResponse() {
|
||||
ClassPathXmlApplicationContext localContext = new ClassPathXmlApplicationContext("multicast/consumer-app.xml");
|
||||
localContext.start();
|
||||
GreetingsService greetingsService = (GreetingsService) localContext.getBean("greetingsService");
|
||||
String hiMessage = greetingsService.sayHi("baeldung");
|
||||
|
||||
assertNotNull(hiMessage);
|
||||
assertEquals("hi, baeldung", hiMessage);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.baeldung.dubbo;
|
||||
|
||||
import com.baeldung.dubbo.remote.GreetingsService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class ResultCacheLiveTest {
|
||||
|
||||
private ClassPathXmlApplicationContext remoteContext;
|
||||
|
||||
@Before
|
||||
public void initRemote() {
|
||||
remoteContext = new ClassPathXmlApplicationContext("multicast/provider-app-special.xml");
|
||||
remoteContext.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProvider_whenConsumerSaysHi_thenGotResponse() {
|
||||
ClassPathXmlApplicationContext localContext = new ClassPathXmlApplicationContext("multicast/consumer-app.xml");
|
||||
localContext.start();
|
||||
GreetingsService greetingsService = (GreetingsService) localContext.getBean("greetingsService");
|
||||
|
||||
long before = System.currentTimeMillis();
|
||||
String hiMessage = greetingsService.sayHi("baeldung");
|
||||
|
||||
long timeElapsed = System.currentTimeMillis() - before;
|
||||
assertTrue(timeElapsed > 5000);
|
||||
assertNotNull(hiMessage);
|
||||
assertEquals("hi, baeldung", hiMessage);
|
||||
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
hiMessage = greetingsService.sayHi("baeldung");
|
||||
timeElapsed = System.currentTimeMillis() - before;
|
||||
assertTrue(timeElapsed < 1000);
|
||||
assertNotNull(hiMessage);
|
||||
assertEquals("hi, baeldung", hiMessage);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.baeldung.dubbo;
|
||||
|
||||
import com.baeldung.dubbo.remote.GreetingsService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class SimpleRegistryLiveTest {
|
||||
|
||||
private ClassPathXmlApplicationContext remoteContext;
|
||||
private ClassPathXmlApplicationContext registryContext;
|
||||
|
||||
@Before
|
||||
public void initRemote() {
|
||||
registryContext = new ClassPathXmlApplicationContext("simple/registry.xml");
|
||||
registryContext.start();
|
||||
|
||||
remoteContext = new ClassPathXmlApplicationContext("simple/provider-app.xml");
|
||||
remoteContext.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProvider_whenConsumerSaysHi_thenGotResponse() {
|
||||
ClassPathXmlApplicationContext localContext = new ClassPathXmlApplicationContext("simple/consumer-app.xml");
|
||||
localContext.start();
|
||||
GreetingsService greetingsService = (GreetingsService) localContext.getBean("greetingsService");
|
||||
String hiMessage = greetingsService.sayHi("baeldung");
|
||||
|
||||
assertNotNull(hiMessage);
|
||||
assertEquals("hi, baeldung", hiMessage);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<!-- provider application meta -->
|
||||
<dubbo:application name="demo-consumer" version="1.0"/>
|
||||
|
||||
<!-- address used to expose provider's service -->
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
|
||||
<!-- remote service proxy, acting like a local bean while invoking -->
|
||||
<dubbo:reference interface="com.baeldung.dubbo.remote.GreetingsService" id="greetingsService" retries="2" timeout="2000" />
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<!-- provider application meta -->
|
||||
<dubbo:application name="demo-consumer" version="1.0"/>
|
||||
|
||||
<!-- address used to expose provider's service -->
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
|
||||
<!-- remote service proxy, acting like a local bean while invoking -->
|
||||
<dubbo:reference interface="com.baeldung.dubbo.remote.GreetingsService" id="greetingsService" retries="2" timeout="10000" loadbalance="roundrobin" />
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<!-- provider application meta -->
|
||||
<dubbo:application name="demo-provider" version="1.0"/>
|
||||
|
||||
<!-- address used to expose provider's service -->
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
|
||||
<!-- protocol and port used to expose service -->
|
||||
<dubbo:protocol name="dubbo" port="20880"/>
|
||||
|
||||
<!-- the service interface to expose -->
|
||||
<dubbo:service interface="com.baeldung.dubbo.remote.GreetingsService" ref="greetingsService" cluster="failsafe"/>
|
||||
|
||||
<!-- declare the local implementation of exposed service interface -->
|
||||
<bean id="greetingsService" class="com.baeldung.dubbo.remote.GreetingsServiceImpl"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<!-- provider application meta -->
|
||||
<dubbo:application name="demo-provider" version="1.0"/>
|
||||
|
||||
<!-- address used to expose provider's service -->
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
|
||||
<!-- protocol and port used to expose service -->
|
||||
<dubbo:protocol name="dubbo" port="20880"/>
|
||||
|
||||
<!-- the service interface to expose -->
|
||||
<dubbo:service interface="com.baeldung.dubbo.remote.GreetingsService" ref="greetingsService" cluster="failover"/>
|
||||
|
||||
<!-- declare the local implementation of exposed service interface -->
|
||||
<bean id="greetingsService" class="com.baeldung.dubbo.remote.GreetingsFailoverServiceImpl"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<!-- provider application meta -->
|
||||
<dubbo:application name="demo-provider" version="1.0"/>
|
||||
|
||||
<!-- address used to expose provider's service -->
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
|
||||
<!-- protocol and port used to expose service -->
|
||||
<dubbo:protocol name="dubbo" port="20881" />
|
||||
|
||||
<!-- the service interface to expose -->
|
||||
<dubbo:service interface="com.baeldung.dubbo.remote.GreetingsService" ref="greetingsService" cluster="failsafe"/>
|
||||
|
||||
<!-- declare the local implementation of exposed service interface -->
|
||||
<bean id="greetingsService" class="com.baeldung.dubbo.remote.GreetingsServiceSpecialImpl"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<!-- provider application meta -->
|
||||
<dubbo:application name="demo-provider" version="1.0"/>
|
||||
|
||||
<!-- address used to expose provider's service -->
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
|
||||
<!-- protocol and port used to expose service -->
|
||||
<dubbo:protocol name="dubbo" port="20881" />
|
||||
|
||||
<!-- the service interface to expose -->
|
||||
<dubbo:service interface="com.baeldung.dubbo.remote.GreetingsService" ref="greetingsService" cluster="failover"/>
|
||||
|
||||
<!-- declare the local implementation of exposed service interface -->
|
||||
<bean id="greetingsService" class="com.baeldung.dubbo.remote.GreetingsServiceSpecialImpl"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,6 @@
|
|||
log4j.rootLogger=INFO, stdout
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<!-- provider application meta -->
|
||||
<dubbo:application name="demo-consumer" version="1.0"/>
|
||||
|
||||
<!-- address used to expose provider's service -->
|
||||
<dubbo:registry address="multicast://224.1.1.1:9090"/>
|
||||
|
||||
<!-- remote service proxy, acting like a local bean while invoking -->
|
||||
<dubbo:reference interface="com.baeldung.dubbo.remote.GreetingsService" id="greetingsService" cache="lru" />
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<!-- provider application meta -->
|
||||
<dubbo:application name="demo-provider" version="1.0"/>
|
||||
|
||||
<!-- address used to expose provider's service -->
|
||||
<dubbo:registry address="multicast://224.1.1.1:9090"/>
|
||||
|
||||
<!-- protocol and port used to expose service -->
|
||||
<dubbo:protocol name="dubbo" port="20881" />
|
||||
|
||||
<!-- the service interface to expose -->
|
||||
<dubbo:service interface="com.baeldung.dubbo.remote.GreetingsService" ref="greetingsService"/>
|
||||
|
||||
<!-- declare the local implementation of exposed service interface -->
|
||||
<bean id="greetingsService" class="com.baeldung.dubbo.remote.GreetingsServiceSpecialImpl"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<!-- provider application meta -->
|
||||
<dubbo:application name="demo-provider" version="1.0"/>
|
||||
|
||||
<!-- address used to expose provider's service -->
|
||||
<dubbo:registry address="multicast://224.1.1.1:9090"/>
|
||||
|
||||
<!-- protocol and port used to expose service -->
|
||||
<dubbo:protocol name="dubbo" port="20880"/>
|
||||
|
||||
<!-- the service interface to expose -->
|
||||
<dubbo:service interface="com.baeldung.dubbo.remote.GreetingsService" ref="greetingsService"/>
|
||||
|
||||
<!-- declare the local implementation of exposed service interface -->
|
||||
<bean id="greetingsService" class="com.baeldung.dubbo.remote.GreetingsServiceImpl"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<!-- provider application meta -->
|
||||
<dubbo:application name="demo-consumer" version="1.0"/>
|
||||
|
||||
<!-- address used to expose provider's service -->
|
||||
<dubbo:registry address="127.0.0.1:9090"/>
|
||||
|
||||
<!-- remote service proxy, acting like a local bean while invoking -->
|
||||
<dubbo:reference interface="com.baeldung.dubbo.remote.GreetingsService" id="greetingsService" cluster="failover" retries="2"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<!-- provider application meta -->
|
||||
<dubbo:application name="demo-provider" version="1.0"/>
|
||||
|
||||
<!-- address used to expose provider's service -->
|
||||
<dubbo:registry address="127.0.0.1:9090"/>
|
||||
|
||||
<!-- protocol and port used to expose service -->
|
||||
<dubbo:protocol name="dubbo" port="20880"/>
|
||||
|
||||
<!-- the service interface to expose -->
|
||||
<dubbo:service interface="com.baeldung.dubbo.remote.GreetingsService" ref="greetingsService"/>
|
||||
|
||||
<!-- declare the local implementation of exposed service interface -->
|
||||
<bean id="greetingsService" class="com.baeldung.dubbo.remote.GreetingsServiceImpl"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<dubbo:application name="simple-registry" />
|
||||
|
||||
<dubbo:protocol port="9090" />
|
||||
|
||||
<dubbo:service interface="com.alibaba.dubbo.registry.RegistryService" ref="registryService" registry="N/A" ondisconnect="disconnect">
|
||||
<dubbo:method name="subscribe"><dubbo:argument index="1" callback="true" /></dubbo:method>
|
||||
<dubbo:method name="unsubscribe"><dubbo:argument index="1" callback="true" /></dubbo:method>
|
||||
</dubbo:service>
|
||||
|
||||
<bean id="registryService" class="com.alibaba.dubbo.registry.simple.SimpleRegistryService" />
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,16 @@
|
|||
## Building
|
||||
|
||||
To build the module, use Maven's `package` goal:
|
||||
|
||||
```
|
||||
mvn clean package
|
||||
```
|
||||
|
||||
The `war` file will be available at `target/remote-debugging.war`
|
||||
|
||||
## Running
|
||||
|
||||
The `war` application is deployed to Apache Tomcat 8 or any other Java Web or Application server.
|
||||
To deploy it to the Apache Tomcat 8 server, drop it in the `tomcat/webapps` directory.
|
||||
|
||||
The service then will be accessible at http://localhost:8080/remote-debugging/hello?name=John
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.stackify</groupId>
|
||||
<artifactId>java-remote-debugging</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.5.8.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>remote-debugging</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,12 @@
|
|||
package com.stackify.debug;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class JavaRemoteDebuggingApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(JavaRemoteDebuggingApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.stackify.debug.config;
|
||||
|
||||
import com.stackify.debug.JavaRemoteDebuggingApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||
|
||||
public class WebInitializer extends SpringBootServletInitializer {
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(JavaRemoteDebuggingApplication.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.stackify.debug.rest;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController("/hello")
|
||||
public class HelloController {
|
||||
|
||||
@GetMapping
|
||||
public String hello(@RequestParam("name") String name) {
|
||||
String message = "Hello, " + name;
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,12 +3,14 @@ package com.baeldung.logback;
|
|||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.core.AppenderBase;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class MapAppender extends AppenderBase<ILoggingEvent> {
|
||||
|
||||
private final Map<String, ILoggingEvent> eventMap = new HashMap<>();
|
||||
private final ConcurrentMap<String, ILoggingEvent> eventMap
|
||||
= new ConcurrentHashMap<>();
|
||||
|
||||
private String prefix;
|
||||
|
||||
|
|
Loading…
Reference in New Issue