Azure功能-AWS RDS Postgres的事件中心 [英] Azure Function - Event Hub to AWS RDS Postgres

查看:54
本文介绍了Azure功能-AWS RDS Postgres的事件中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我工作的地方,我们试图使用Azure函数从事件中心获取JSON字符串消息并将其插入AWS的Postgres RDS中.不幸的是,我们暂时必须使用Postgres RDS来保留数据,但是将来可能会更改为Azure技术.

Where I work, we are trying to use an Azure Function to take a JSON string message from an Event Hub and insert it into Postgres RDS in AWS. Unfortunately, we have to use Postgres RDS for the time being to persist data but this will likely change to an Azure technology in future.

我能够将功能绑定到事件中心,并且可以成功接收消息.

I am able to get the Function bound to an Event Hub and can successfully receive messages.

run.csx

#r "System.Data"

using System;
using System.Data;
using Npgsql;

public static void Run(string myEventHubMessage, TraceWriter log)
{
    log.Info($"C# Event Hub trigger function processed a message: 
    {myEventHubMessage}");

    using (NpgsqlConnection connection = new NpgsqlConnection(
    "Host=host;Port=5432;Database=database;Username=username;Password=password;Timeout=300"))
    {
        try
        {
            log.Info("Opening connection to Postgres...");
            connection.Open();
            log.Info("Connection open.");
        }
        catch (Exception ex)
        {
            log.Info($"Failed to open connection to Postgres. EXCEPTION: 
            {ex.Message}");
            throw;
        }  
    }
}

project.json

project.json

{
  "frameworks": {
  "net46":{
  "dependencies": {
    "Npgsql": "3.2.2",
   }
  }
 }
}

我正在使用Npgsql尝试连接到Postgres,但似乎无法连接,在日志中出现以下错误:

I am using Npgsql to try to connect to Postgres but it can't seem to connect giving the following error in the logs:

2017-04-27T09:58:30.710 Failed to open connection to Postgres. EXCEPTION: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

我知道该数据库可用于连接,并且我尝试在连接字符串中增加Timeout等,但是没有运气.

I know this database is available to connect to and I have tried upping the Timeout etc in the connection string but no luck.

这实际上可行吗?

非常感谢.

推荐答案

很有可能不是超时,而是位于Azure Web App和AWS Database之间的防火墙,它阻止了连接.

Most probably it's not a timeout, but a firewall sitting between Azure Web App and AWS Database, which blocks the connection.

Azure不会限制出站连接,至少不会限制到端口5432.

Azure does not restrict outbound connections, at least not to port 5432.

因此,我想这是AWS对配置的IP范围有限制的人.尝试将Azure IP范围添加到那里的白名单.

So, I guess that's AWS who has a restriction on IP range configured. Try adding your Azure IP range to the white list there.

Azure门户似乎没有显示功能应用程序的出站IP范围,但是我可以在 Azure资源浏览器.资源的路径将类似于

Azure portal doesn't seem to show the Outbound IP ranges for a Function App, but I'm able to see them in Azure Resource Explorer. The path to your resource will look like

http://resources.azure.com/subscriptions/{subscriptionid}/resourceGroups/{webappplan}
/providers/Microsoft.Web/sites/{functionapp}

搜索类似的属性

"outboundIpAddresses": "104.46.38.91,104.46.38.110,104.46.35.12,23.97.218.73"

更新:出于某种原因,门户网站中未显示出站IP地址.由于Function App实例可能处于不同的比例尺集中,因此不能保证它们是稳定的.参见此答案.

UPDATE: The outbound IP address is not shown in the portal for a reason. They are not guaranteed to be stable, since Function App instances may be in different scale sets. See this answer.

这篇关于Azure功能-AWS RDS Postgres的事件中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆