在我工作的地方,我們嘗試使用Azure功能從事件中心接收JSON字符串消息並將其插入到AWS中的Postgres RDS中。不幸的是,我們必須暫時使用Postgres RDS來保存數據,但未來這可能會變成Azure技術。Azure功能 - AWS RDS的事件中心Postgres
我能夠將函數綁定到事件中心並可以成功接收消息。
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
{
"frameworks": {
"net46":{
"dependencies": {
"Npgsql": "3.2.2",
}
}
}
}
我使用到Npgsql的嘗試連接到Postgres的,但它似乎無法連接給下面的錯誤日誌:
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
我知道這個數據庫可以連接到,我已經嘗試加大超時等連接字符串,但沒有運氣。
這實際上有可能嗎?
非常感謝。
Azure不應限制您的傳出連接...也許AWS配置了網絡限制?嘗試製作一個控制檯應用程序,並從辦公室,家庭,Azure Web Job等不同位置運行它,以查看它是否可以在任何地方使用。 – Mikhail
@米哈伊爾感謝米哈伊爾的回覆。你提到的實際上可能是這個問題。我認爲我們被限制在允許訪問數據庫的IP範圍內。我會看看我能否解決這個問題並回復你。 – Chris
在azure中,我們有防火牆設置來限制外部連接到SQL Server,但您可以添加IP以允許某人連接到您的SQL Server,但AWS可能會有這樣的設置。 –