如何在实现重试策略时捕获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
最满意答案
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 ...
-
在.net 2.0中无法接收串行数据,使用rs232到rs485转换器(Can't receive serial data in .net 2.0, using rs232 to rs485 converter)[2022-01-18]
事实证明(经过数小时的研究和尝试),设定这一点: .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 ... -
JavaME RaspBerryPi UART无法从RS485接收数据(JavaME RaspBerryPi UART can't receive data from RS485)[2022-05-20]
首先,您必须确保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协议(Custom RS485 Protocols)[2022-05-12]
通过RS485发送数据包不是可靠的通信。 无论如何,你将不得不处理丢失的数据包。 当然,您不必重新发明TCP。 但是您必须通过超时监控和序列号来检测丢失的数据包。 在简单的应用程序中,这可以在应用程序级别完成,这使您远离TCP的复杂性。 当您的轮询模型丢弃具有无效校验和的所有数据包时,可以更轻松地集成这些数据包。 如果要检查可能由热插拔或行为不当设备引起的碰撞,可能会有一些改进。 某些硬件允许回读自己的传输。 如果发现发送数据和接收数据之间存在差异,则可以假设发生冲突并重复发送数据包。 这还需要一种序列编号 ... -
Android Studio Modbus rs485串行连接MacosX(Android Studio Modbus rs485 serial connection MacosX)[2022-12-28]
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.