小编Rya*_*via的帖子

使用 RabbitMq MessageListenerContainer 的 Reactor Flux 超时

使用热发布者模型,在云环境中大约有 50% 的时间会发生以下超时异常:

[ERROR] reactor.core.scheduler.Schedulers                  - Scheduler worker in group main failed with an uncaught exception
reactor.core.Exceptions$ErrorCallbackNotImplemented: java.util.concurrent.TimeoutException: Did not observe any item or terminal signal within 300000ms (and no fallback has been configured)
Caused by: java.util.concurrent.TimeoutException: Did not observe any item or terminal signal within 300000ms (and no fallback has been configured)
reactor.core.publisher.FluxTimeout$TimeoutMainSubscriber.handleTimeout(FluxTimeout.java:289)
reactor.core.publisher.FluxTimeout$TimeoutMainSubscriber.doTimeout(FluxTimeout.java:274)
reactor.core.publisher.FluxTimeout$TimeoutTimeoutSubscriber.onNext(FluxTimeout.java:396)
reactor.core.publisher.StrictSubscriber.onNext(StrictSubscriber.java:89)
datadog.trace.instrumentation.reactor.core.TracingSubscriber.onNext(TracingSubscriber.java:75)
reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:73)
datadog.trace.instrumentation.reactor.core.TracingSubscriber.onNext(TracingSubscriber.java:75)
reactor.core.publisher.MonoDelay$MonoDelayRunnable.run(MonoDelay.java:117)
reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java.base/java.lang.Thread.run(Thread.java:834)
Run Code Online (Sandbox Code Playgroud)

但是我不能在本地复制这个。我的主要理论是原因发生在通量的创建过程中,并且在Flux和之间发生了一些不好的事情MessageListenerContainer。创作看起来像:

@Bean
public Flux<RabbitEventPublishEnvelope> masterFlux(
        Queue eventQueue,
        ObjectMapper …
Run Code Online (Sandbox Code Playgroud)

java spring rabbitmq project-reactor

8
推荐指数
1
解决办法
464
查看次数

防止非 SELECT SQL 语句

我允许用户输入他们自己的 SQL 语句来执行,但前提是它是一个 SELECT 语句。有没有办法检测 SQL 语句是否与此不同,即 ALTER、INSERT、DROP 等?我会担心其他问题,例如查询锁定表等,但现在这更多是概念证明。我可以将运行应用程序的服务器上的服务帐户限制为对数据库具有只读权限,但我有兴趣在应用程序中处理它。

这是我通过检测查询的第一个单词来解决它的方法,但这似乎很脆弱。有没有更干净的方法来进行这种检测?

public void ExecuteQuery(string connectionString, int id)
{
    //The SQL statement will be user input
    var sql = "SELECT ColumnA, ColumnB, ColumnC FROM MyTable where MyTableId = @Id";
    var split = sql.Split(' ');

    if (split[0].ToUpper() != "SELECT") Console.WriteLine("Only use a SELECT statement.");
    else
    {
        using (var connection = new SqlConnection(connectionString))
        using (var cmd = new SqlCommand(sql, connection))
        {
            cmd.Parameters.AddWithValue("@Id", SqlDbType.Int);
            cmd.Parameters["@Id"].Value = id;
            connection.Open();

            var reader = cmd.ExecuteReader();
            try
            {
                while …
Run Code Online (Sandbox Code Playgroud)

c# sql-server

5
推荐指数
1
解决办法
397
查看次数

标签 统计

c# ×1

java ×1

project-reactor ×1

rabbitmq ×1

spring ×1

sql-server ×1