首页 \ 问答 \ 如何在实现重试策略时捕获RetryLimitExceeded(How to catch RetryLimitExceeded when implementing a retry policy)

如何在实现重试策略时捕获RetryLimitExceeded(How to catch RetryLimitExceeded when implementing a retry policy)

我正在尝试为Azure中的数据库关联瞬态错误实现重试策略,但不了解如何在此特定上下文中捕获RetryLimitExceeded类型的错误。

详细说明 - 下面关于msdn的文章描述了将其设置为实体框架DbConfiguration的过程,这很容易。 但是它还指定我们应该处理RetryLimitExceeded异常,如果错误不是瞬态相关的,或者尝试次数超过限制,则可能抛出该异常。

https://msdn.microsoft.com/en-us/data/dn456835.aspx

我不明白我应该如何捕获异常 - 我应该在try catch中包装SetExecutionStrategy还是我希望全局处理这种错误? 或者是其他东西?

public class IntranetDBConfiguration : DbConfiguration
{
    public IntranetDBConfiguration()
    {
        SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy()); //default is 5 retries up to 30 seconds.
    }
}

I'm trying to implement a retry policy for database releated transient errors in Azure but don't understand how to catch errors of the type RetryLimitExceeded in this paricular context.

To elaborate - the article below on msdn describes the process of setting this up as a Entity Framework DbConfiguration which was easy enough. It however also specififies that we should handle the RetryLimitExceeded exception that might be thrown if the error is not transient related or if the number of tries exceeds the limit.

https://msdn.microsoft.com/en-us/data/dn456835.aspx

I don't understand how I should catch exceptions - should I wrap the SetExecutionStrategy in a try catch or am I expected to handle that kind of error globally? Or something else?

public class IntranetDBConfiguration : DbConfiguration
{
    public IntranetDBConfiguration()
    {
        SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy()); //default is 5 retries up to 30 seconds.
    }
}

原文:https://stackoverflow.com/questions/35357933
更新时间:2023-03-06 19:03

最满意答案

modbus-tk使您可以编写自己的modbus从站。

下面是一个运行RTU服务器的示例,该服务器具有从地址0开始的100个保持寄存器:

import sys

import modbus_tk
import modbus_tk.defines as cst
from modbus_tk import modbus_rtu
import serial


PORT = 0
#PORT = '/dev/ptyp5'

def main():
    """main"""
    logger = modbus_tk.utils.create_logger(name="console", record_format="%(message)s")

    #Create the server
    server = modbus_rtu.RtuServer(serial.Serial(PORT))

    try:
        logger.info("running...")
        logger.info("enter 'quit' for closing the server")

        server.start()

        slave_1 = server.add_slave(1)
        slave_1.add_block('0', cst.HOLDING_REGISTERS, 0, 100)
        while True:
            cmd = sys.stdin.readline()
            args = cmd.split(' ')

            if cmd.find('quit') == 0:
                sys.stdout.write('bye-bye\r\n')
                break

    finally:
        server.stop()

if __name__ == "__main__":
    main()

我希望它有帮助


modbus-tk makes possible to write your own modbus slave.

Here is an example running a RTU server with 100 holding registers starting at adress 0 :

import sys

import modbus_tk
import modbus_tk.defines as cst
from modbus_tk import modbus_rtu
import serial


PORT = 0
#PORT = '/dev/ptyp5'

def main():
    """main"""
    logger = modbus_tk.utils.create_logger(name="console", record_format="%(message)s")

    #Create the server
    server = modbus_rtu.RtuServer(serial.Serial(PORT))

    try:
        logger.info("running...")
        logger.info("enter 'quit' for closing the server")

        server.start()

        slave_1 = server.add_slave(1)
        slave_1.add_block('0', cst.HOLDING_REGISTERS, 0, 100)
        while True:
            cmd = sys.stdin.readline()
            args = cmd.split(' ')

            if cmd.find('quit') == 0:
                sys.stdout.write('bye-bye\r\n')
                break

    finally:
        server.stop()

if __name__ == "__main__":
    main()

I hope it helps

相关问答

更多
  • modbus-tk使您可以编写自己的modbus从站。 下面是一个运行RTU服务器的示例,该服务器具有从地址0开始的100个保持寄存器: import sys import modbus_tk import modbus_tk.defines as cst from modbus_tk import modbus_rtu import serial PORT = 0 #PORT = '/dev/ptyp5' def main(): """main""" logger = modbus ...
  • `每当我向控制器发送“0x00”时,都会收到“0xFF”。 然后我发送“0x01”,在控制器上收到“0xFD”。 这似乎表明你的极性是相反的。 请参见数据手册中的U1MODEbits.URXINV和U1STAbits.UTXINV位或系列参考手册( http://ww1.microchip.com/downloads/en/DeviceDoc/70000582e.pdf )。 `Whenever I send "0x00" to controller, "0xFF" is received. Then I ...
  • 事实证明(经过数小时的研究和尝试),设定这一点: .DtrEnable = True 诀窍。 我以前从来没有必须使用DTR属性,但无论是与我正在使用的这一个设备有关的问题,还是我错过的其他东西 - 就是这样做的。 我认为这可能会挽救别人头痛的道路。 It turns out (after hours of researching and trying) that setting this: .DtrEnable = True did the trick. I've never had to use the ...
  • 首先,您必须确保Linux控制台尚未使用串行端口。 以下是禁用此功能的方法: 编辑/etc/inittab并通过在其前面添加一个#字符来禁用以下行 T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 然后重启。 如果这仍然不起作用,那么您可以尝试使用提升的权限执行JavaME运行时: sudo ./runSuite.sh 如果这样做,某处存在权限问题。 最后,您应该尝试获取最新版本的JavaME(目前为8.1)。 First, you ...
  • 正如@Richard Chambers的评论中所提到的,您正在使用未初始化的结构。 你应该做 struct serial_rs485 rs485conf = {0}; 但是,正如所讨论的那样,并没有解决问题。 引用您引用的内核文档 某些CPU / UART(例如,Atmel AT91或16C950 UART)包含内置半双工模式,能够通过切换RTS或DTR信号自动控制线路方向。 这可用于控制外部半双工硬件,如RS485收发器...... 然而,该器件有一个专用引脚TXDEN。 引自数据表第4.3.3节 对于 ...
  • 通过RS485发送数据包不是可靠的通信。 无论如何,你将不得不处理丢失的数据包。 当然,您不必重新发明TCP。 但是您必须通过超时监控和序列号来检测丢失的数据包。 在简单的应用程序中,这可以在应用程序级别完成,这使您远离TCP的复杂性。 当您的轮询模型丢弃具有无效校验和的所有数据包时,可以更轻松地集成这些数据包。 如果要检查可能由热插拔或行为不当设备引起的碰撞,可能会有一些改进。 某些硬件允许回读自己的传输。 如果发现发送数据和接收数据之间存在差异,则可以假设发生冲突并重复发送数据包。 这还需要一种序列编号 ...
  • RXTX不能在macbook上运行android studio。 使用Windows PC和问题解决了。 RXTX not working android studio on macbook. Use windows PC and problem solved.
  • LTE-485(RS-485线路驱动器)具有“驱动器使能引脚”,必须将其置位才能进行传输。 您必须在开始发送字符之前断言它,并且必须在最后一个字节完成传输后取消断言(为了能够接收数据而取消断言它,或者让其他设备驱动它如果您不想接收,并且您没有任何其他愿意传输的设备,您可以保持声明。 在您的代码中有: RS485_CTRL = 1; //启用驱动程序 U4TXREG = rs485Char; 您使用RS485_CTRL = 1启用驱动程序,然后加载UART移位寄存器,但也许您不会等待所有数据移出的时间。 为了 ...
  • 解决方案是在命令前加上这样的地址编号 Public Property GateAddress As String = "A007" SerialPort.Write(GateAddress + "Some ASCII Command" + vbCrLf) The solution is to prefix the command with the address number like this Public Property GateAddress As String = "A007" SerialPo ...
  • 转发器将地址封装在客户端的无线电网络上,因此当有多个客户端时,代理可以回复正确的客户端。 The forwarder encapsulates the address on the radio network of the client, so the broker can reply to the right client when there is more than one client.

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。