首页 \ 问答 \ 如何在特定的@FeignClient上禁用尤里卡查找(How to disable eureka lookup on specific @FeignClient)

如何在特定的@FeignClient上禁用尤里卡查找(How to disable eureka lookup on specific @FeignClient)

我有一个微服务,主要使用@FeignClient与其他微服务交谈。 使用Eureka的服务发现机制,这很美妙。

现在我迫切需要使用@FeignClient连接到外部系统,并仍然使用如下所示的配置执行负载平衡。

Feign client

@FeignClient("externalServers")
public interface ExternalServersClient {
    @RequestMapping(method = RequestMethod.GET, value = "/someExternalUrl")
    ResponseEntity<Object> callExternalServer();
}

application.yml

externalServers:
  ribbon:
    listOfServers: server1:18201,server2:18201

从我所经历的许多文档中,建议禁用eureka以允许从可用的listOfServers中获取负载均衡。 我确实遵循了这一点,并使用以下配置来禁用它。

application.yml

ribbon:
  eureka:
    enabled: false

这使我能够为假装客户端目标外部系统执行负载平衡,但所有其他需要使用服务发现的假装客户端都破了。

有没有办法为外部系统单独禁用eureka for feign客户端设置,但允许其为其他客户端正常运行?

提前致谢!


I have a microservice that uses @FeignClient predominantly to talk to other micro-services. This works beautifuly using Eureka's service discovery mechanism.

Now I have a pressing need to use a @FeignClient to connect to an external system and still perform load balancing using configurations as shown below.

Feign client:

@FeignClient("externalServers")
public interface ExternalServersClient {
    @RequestMapping(method = RequestMethod.GET, value = "/someExternalUrl")
    ResponseEntity<Object> callExternalServer();
}

application.yml:

externalServers:
  ribbon:
    listOfServers: server1:18201,server2:18201

From many documentations that I have gone through, it is adviced to disable eureka to allow loadbalancing to be picked up from available listOfServers. I did follow that up and used following configuration to disable it.

application.yml:

ribbon:
  eureka:
    enabled: false

This allowed me to perform loadbalancing for feign client targeting external systems but all other feign clients that need to use service discovery broke.

Is there any way to disable eureka for feign client setup for external system alone but allow it to function normally for other clients?

Thanks in advance!


原文:https://stackoverflow.com/questions/38360182
更新时间:2024-04-22 10:04

最满意答案

是的,但您需要使用GraphicsDeviceGraphicsEnvironmentGraphicsConfiguration API

Toolkit#getScreenSize就是这样,它返回屏幕的大小,但它不包括所有的OS元素,比如Dock,它占用了额外的空间

坐在码头上

所以,这是一堆库代码,旨在找到特定组件所在的GraphicsDevice ,或者,默认的GraphicsDevice ...库代码;)

public static Rectangle getDefaultScreenBounds() {
    return getScreenBounds(null, true);
}

public static Rectangle getScreenBounds(Component comp, boolean acceptDefault) {
    Rectangle bounds = getScreenBounds(comp);
    if ((bounds == null || (bounds.x == 0 && bounds.y == 0 && bounds.width == 0 && bounds.height == 0)) && acceptDefault) {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        bounds = gd.getDefaultConfiguration().getBounds();
    }
    return bounds;
}

public static Rectangle getScreenBounds(Component comp) {
    Rectangle bounds = new Rectangle(0, 0, 0, 0);
    GraphicsDevice gd = getGraphicsDevice(comp);

    if (gd != null) {
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        bounds = gc.getBounds();
    }
    return bounds;
}

public static GraphicsDevice getGraphicsDevice(Component comp) {
    GraphicsDevice device = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice lstGDs[] = ge.getScreenDevices();
    List<GraphicsDevice> lstDevices = new ArrayList<>(lstGDs.length);
    if (comp != null && comp.isVisible()) {
        Rectangle parentBounds = comp.getBounds();
        /*
         * If the component is not a window, we need to find its location on the
         * screen...
         */
        if (!(comp instanceof Window)) {
            Point p = new Point(0, 0);
            SwingUtilities.convertPointToScreen(p, comp);
            parentBounds.setLocation(p);
        }

        for (GraphicsDevice gd : lstGDs) {
            GraphicsConfiguration gc = gd.getDefaultConfiguration();
            Rectangle screenBounds = gc.getBounds();
            if (screenBounds.intersects(parentBounds)) {
                lstDevices.add(gd);
            }
        }
        if (lstDevices.size() == 1) {
            device = lstDevices.get(0);
        } else {
            GraphicsDevice gdMost = null;
            float maxArea = 0;

            for (GraphicsDevice gd : lstDevices) {
                GraphicsConfiguration gc = gd.getDefaultConfiguration();
                Rectangle bounds = gc.getBounds();

                Rectangle2D intBounds = bounds.createIntersection(parentBounds);
                float perArea = (float) ((intBounds.getWidth() * intBounds.getHeight()) / (parentBounds.width * parentBounds.height));
                if (perArea > maxArea) {
                    maxArea = perArea;
                    gdMost = gd;
                }
            }
            if (gdMost != null) {
                device = gdMost;
            }
        }
    }

    return device;
}

而且,这就是你如何使用它......

package javaapplication1.pkg169;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Test {

    public static void main(String[] args) {
        new Test();
    }

    public Test() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                }

                JFrame frame = new JFrame("Testing");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(new TestPane());
                frame.pack();
                Rectangle bounds = getDefaultScreenBounds();
                System.out.println(bounds);
                int x = bounds.x + ((bounds.width - frame.getWidth()) / 2);
                frame.setLocation(x, bounds.y + (bounds.height - frame.getHeight()));
                frame.setVisible(true);
            }
        });
    }

    public class TestPane extends JPanel {

        public TestPane() {
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(200, 200);
        }

    }

    public static Rectangle getDefaultScreenBounds() {
        return getScreenBounds(null, true);
    }

    public static Rectangle getScreenBounds(Component comp, boolean acceptDefault) {
        Rectangle bounds = getScreenBounds(comp);
        if ((bounds == null || (bounds.x == 0 && bounds.y == 0 && bounds.width == 0 && bounds.height == 0)) && acceptDefault) {
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice gd = ge.getDefaultScreenDevice();
            bounds = gd.getDefaultConfiguration().getBounds();
        }
        return bounds;
    }

    public static Rectangle getScreenBounds(Component comp) {
        Rectangle bounds = new Rectangle(0, 0, 0, 0);
        GraphicsDevice gd = getGraphicsDevice(comp);

        if (gd != null) {
            GraphicsConfiguration gc = gd.getDefaultConfiguration();
            bounds = gc.getBounds();
        }
        return bounds;
    }

    public static GraphicsDevice getGraphicsDevice(Component comp) {
        GraphicsDevice device = null;
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice lstGDs[] = ge.getScreenDevices();
        List<GraphicsDevice> lstDevices = new ArrayList<>(lstGDs.length);
        if (comp != null && comp.isVisible()) {
            Rectangle parentBounds = comp.getBounds();
            /*
             * If the component is not a window, we need to find its location on the
             * screen...
             */
            if (!(comp instanceof Window)) {
                Point p = new Point(0, 0);
                SwingUtilities.convertPointToScreen(p, comp);
                parentBounds.setLocation(p);
            }

            for (GraphicsDevice gd : lstGDs) {
                GraphicsConfiguration gc = gd.getDefaultConfiguration();
                Rectangle screenBounds = gc.getBounds();
                if (screenBounds.intersects(parentBounds)) {
                    lstDevices.add(gd);
                }
            }
            if (lstDevices.size() == 1) {
                device = lstDevices.get(0);
            } else {
                GraphicsDevice gdMost = null;
                float maxArea = 0;

                for (GraphicsDevice gd : lstDevices) {
                    GraphicsConfiguration gc = gd.getDefaultConfiguration();
                    Rectangle bounds = gc.getBounds();

                    Rectangle2D intBounds = bounds.createIntersection(parentBounds);
                    float perArea = (float) ((intBounds.getWidth() * intBounds.getHeight()) / (parentBounds.width * parentBounds.height));
                    if (perArea > maxArea) {
                        maxArea = perArea;
                        gdMost = gd;
                    }
                }
                if (gdMost != null) {
                    device = gdMost;
                }
            }
        }

        return device;
    }

}

Yes, but you need to make use of the GraphicsDevice, GraphicsEnvironment and GraphicsConfiguration APIs

Toolkit#getScreenSize does just that, it returns the size of the screen, but it doesn't include all the OS elements, like the dock, which take up additional space

Sitting upon the dock

So, this is a bunch of library code, designed to find the GraphicsDevice a particular component resides on, or, the default GraphicsDevice ... library code ;)

public static Rectangle getDefaultScreenBounds() {
    return getScreenBounds(null, true);
}

public static Rectangle getScreenBounds(Component comp, boolean acceptDefault) {
    Rectangle bounds = getScreenBounds(comp);
    if ((bounds == null || (bounds.x == 0 && bounds.y == 0 && bounds.width == 0 && bounds.height == 0)) && acceptDefault) {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        bounds = gd.getDefaultConfiguration().getBounds();
    }
    return bounds;
}

public static Rectangle getScreenBounds(Component comp) {
    Rectangle bounds = new Rectangle(0, 0, 0, 0);
    GraphicsDevice gd = getGraphicsDevice(comp);

    if (gd != null) {
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        bounds = gc.getBounds();
    }
    return bounds;
}

public static GraphicsDevice getGraphicsDevice(Component comp) {
    GraphicsDevice device = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice lstGDs[] = ge.getScreenDevices();
    List<GraphicsDevice> lstDevices = new ArrayList<>(lstGDs.length);
    if (comp != null && comp.isVisible()) {
        Rectangle parentBounds = comp.getBounds();
        /*
         * If the component is not a window, we need to find its location on the
         * screen...
         */
        if (!(comp instanceof Window)) {
            Point p = new Point(0, 0);
            SwingUtilities.convertPointToScreen(p, comp);
            parentBounds.setLocation(p);
        }

        for (GraphicsDevice gd : lstGDs) {
            GraphicsConfiguration gc = gd.getDefaultConfiguration();
            Rectangle screenBounds = gc.getBounds();
            if (screenBounds.intersects(parentBounds)) {
                lstDevices.add(gd);
            }
        }
        if (lstDevices.size() == 1) {
            device = lstDevices.get(0);
        } else {
            GraphicsDevice gdMost = null;
            float maxArea = 0;

            for (GraphicsDevice gd : lstDevices) {
                GraphicsConfiguration gc = gd.getDefaultConfiguration();
                Rectangle bounds = gc.getBounds();

                Rectangle2D intBounds = bounds.createIntersection(parentBounds);
                float perArea = (float) ((intBounds.getWidth() * intBounds.getHeight()) / (parentBounds.width * parentBounds.height));
                if (perArea > maxArea) {
                    maxArea = perArea;
                    gdMost = gd;
                }
            }
            if (gdMost != null) {
                device = gdMost;
            }
        }
    }

    return device;
}

And, this is how you might use it...

package javaapplication1.pkg169;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Test {

    public static void main(String[] args) {
        new Test();
    }

    public Test() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                }

                JFrame frame = new JFrame("Testing");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(new TestPane());
                frame.pack();
                Rectangle bounds = getDefaultScreenBounds();
                System.out.println(bounds);
                int x = bounds.x + ((bounds.width - frame.getWidth()) / 2);
                frame.setLocation(x, bounds.y + (bounds.height - frame.getHeight()));
                frame.setVisible(true);
            }
        });
    }

    public class TestPane extends JPanel {

        public TestPane() {
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(200, 200);
        }

    }

    public static Rectangle getDefaultScreenBounds() {
        return getScreenBounds(null, true);
    }

    public static Rectangle getScreenBounds(Component comp, boolean acceptDefault) {
        Rectangle bounds = getScreenBounds(comp);
        if ((bounds == null || (bounds.x == 0 && bounds.y == 0 && bounds.width == 0 && bounds.height == 0)) && acceptDefault) {
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice gd = ge.getDefaultScreenDevice();
            bounds = gd.getDefaultConfiguration().getBounds();
        }
        return bounds;
    }

    public static Rectangle getScreenBounds(Component comp) {
        Rectangle bounds = new Rectangle(0, 0, 0, 0);
        GraphicsDevice gd = getGraphicsDevice(comp);

        if (gd != null) {
            GraphicsConfiguration gc = gd.getDefaultConfiguration();
            bounds = gc.getBounds();
        }
        return bounds;
    }

    public static GraphicsDevice getGraphicsDevice(Component comp) {
        GraphicsDevice device = null;
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice lstGDs[] = ge.getScreenDevices();
        List<GraphicsDevice> lstDevices = new ArrayList<>(lstGDs.length);
        if (comp != null && comp.isVisible()) {
            Rectangle parentBounds = comp.getBounds();
            /*
             * If the component is not a window, we need to find its location on the
             * screen...
             */
            if (!(comp instanceof Window)) {
                Point p = new Point(0, 0);
                SwingUtilities.convertPointToScreen(p, comp);
                parentBounds.setLocation(p);
            }

            for (GraphicsDevice gd : lstGDs) {
                GraphicsConfiguration gc = gd.getDefaultConfiguration();
                Rectangle screenBounds = gc.getBounds();
                if (screenBounds.intersects(parentBounds)) {
                    lstDevices.add(gd);
                }
            }
            if (lstDevices.size() == 1) {
                device = lstDevices.get(0);
            } else {
                GraphicsDevice gdMost = null;
                float maxArea = 0;

                for (GraphicsDevice gd : lstDevices) {
                    GraphicsConfiguration gc = gd.getDefaultConfiguration();
                    Rectangle bounds = gc.getBounds();

                    Rectangle2D intBounds = bounds.createIntersection(parentBounds);
                    float perArea = (float) ((intBounds.getWidth() * intBounds.getHeight()) / (parentBounds.width * parentBounds.height));
                    if (perArea > maxArea) {
                        maxArea = perArea;
                        gdMost = gd;
                    }
                }
                if (gdMost != null) {
                    device = gdMost;
                }
            }
        }

        return device;
    }

}

相关问答

更多
  • 在PC上安装MAC OSX[2022-02-21]

    楼上说的全是废话,你的配置可以安装10.6了,但10.6的驱动不好找,所以你完全可以安装10.5,我给你推荐10.5.7版本,用iATKOSV7+硬盘安装助手+变色龙引导菜单进行安装,安装之前需要准备以下东西: 1:给你的电脑安装一个Windows XP或者 PE系统做部署使用; 2:了解你电脑的显卡芯片具体型号(当然,如果你是ATI的显卡那就只有一个选择,只能进入系统在安装合适的驱动了),输入设备型号,这两个很关键;否则你安装安后会有苹果在嘴边却吃不到的感觉; 3:足够的耐心和严谨的态度; 现在开始~ 1 ...
  • 正如moshbear上面评论的那样, dylib文件是在Mac OS X上打包共享库的方式。要使用这样的共享库,需要将两个开关传递给编译器-L和-l 。 第一个将包含dylib的目录添加到链接器的库搜索路径,第二个指定要链接的库。 这样的东西,对于一个位于/usr/mylibs的虚构的/usr/mylibs : clang code.c -L/usr/mylibs -lfoo As moshbear commented above, dylib files are how shared libraries ...
  • OS X不是Linux。 OS X是UNIX。 较低级别的系统API非常相似(在许多情况下相同) - C,'nix,POSIX等。 使用这些接口的程序可以轻松移植到另一个程序(考虑两者兼容的库,几乎不需要平台特定功能)。 当然有差异。 OS X内核是一个微内核(Darwin),而Linux是单片的。 超出核心用户 - 土地层的分歧发生得非常快,特别是用户界面。 OS X is not Linux. OS X is UNIX. The lower level system APIs are very simi ...
  • 在Swing中,实际上并未使用本机OS组件。 Mac上默认的“Aqua”外观尝试尽可能地匹配本机外观,但它实际上只是用Java2D绘制内容。 因此,例如,默认按钮的脉冲发光未实现。 您可以在窗口上设置一些客户端属性以影响其外观,但“标题工具栏”似乎不是一个选项: http://developer.apple.com/library/mac/#technotes/tn2007/tn2196.html#//apple_ref/doc/uid/DTS10004439 一种选择是切换到使用Quaqua外观。 我自己 ...
  • 它不是通过mac端口安装的,所以端口不知道它。 您可以通过端口进行安装,也可以通过导轨使用Mac上已安装的导轨。 It's not installed via mac ports, so port doesn't know about it. You could either do an install via port or get rails to use the one that's installed on the Mac already.
  • 以下是在Mac OSX机器上正确安装和测试YAWS(另一个Web服务器)的步骤: 安装: 访问http://yaws.hyber.org/download/ 获取最新来源 - 例如'yaws-X.XX.tar.gz'。 解压缩它(对于本教程,我们假设/ Users / Name / Desktop / yaws /)。 打开终端(可在Applications / Utilities中找到)。 键入:'cd /Users/Name/Desktop/yaws/yaws-X.XX/'(不含引号)。 键入:'./c ...
  • PYTHONPATH不会影响您是否获得SyntaxError - 只是一个ImportError 。 所以,如果你得到一个SyntaxError ,你的代码就会遇到另一个问题。 请发布代码,我们会指出它。 编辑:您的错误在此行: @app.route('/proPass', method ='POST') @指定一个装饰器,它仅在函数定义( def ),类定义( class )或其他装饰器之前的行上有效。 它显示了open行的第一个字符的错误,因为它期望在那里有一个函数或类定义。 有关装饰器的更多信息,请 ...
  • 有多种选择。 启动 C 服务 Cocoa中的NSWorkspace和NSTask 。 open命令行实用程序。 There are a variety of options. Launch Services for C. NSWorkspace & NSTask in Cocoa. The open command-line utility.
  • 您的开发人员工具未正确安装。 我建议安装Xcode 4。 Your developer tools are not installed correctly. I recommend installing Xcode 4.
  • 是的,但您需要使用GraphicsDevice , GraphicsEnvironment和GraphicsConfiguration API Toolkit#getScreenSize就是这样,它返回屏幕的大小,但它不包括所有的OS元素,比如Dock,它占用了额外的空间 所以,这是一堆库代码,旨在找到特定组件所在的GraphicsDevice ,或者,默认的GraphicsDevice ...库代码;) public static Rectangle getDefaultScreenBounds() { ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。