ruby-on-rails - rails 在两个 localhost 之间接收 webhook
问题描述
我有一个发送带有数据的 webhook (localhost:3000) 的 rails 应用程序。之前,我使用在线 webhook 监视器 (Pipedream),但现在我想构建第二个 rails 应用程序来接收数据 (localhost:3000 -> localhost:3300)。我已经创建了一个路由 /webhook/receive 和它的控制器,但从 localhost:3000 什么也没得到。
我做错了什么?
那是我的第一个应用程序:
def send_create_webhook(webhook_url)
company = User.find_by(email: 'test1@test.de').company_account
webhook_url = 'tcp://0.0.0.0:3300/data/receive'
SendWebhookJob.perform_later(webhook_url, {
subscription: {
type: "#{@tool.title} successfully subscribed",
date: "#{Time.zone.now}",
subscribed: Time.now.strftime("%Y-%d-%m %H:%M:%S %Z"),
user: {
company: "#{company.title}",
name: current_user.name,
email: current_user.email,
}
}
})
end
class SendWebhookJob < ApplicationJob
queue_as :default
WEBHOOK_RETRIES = 3
def perform(webhook_url, data, retry_count = 0)
p "COUNT #{retry_count} : #{Time.zone.now} : Sending data to #{webhook_url}"
# make a request
begin
response = HTTP.post(webhook_url, json:data)
successful = response.code == 200
rescue StandardError => e
successful = false
end
if successful
p "SUCCESSFUL WEBHOOK"
elsif retry_count < WEBHOOK_RETRIES
wait = 2 ** retry_count
SendWebhookJob.set(wait: wait.seconds).perform_later(webhook_url, data,retry_count + 1)
end
end
end
我刚刚创建的第二个应用程序:
resources :data do
get :receive
post :receive
end
def DataController < ApplicationController
require "http"
def receive
response = HTTP.get('tcp://0.0.0.0:3000')
end
end
解决方案
推荐阅读
- javascript - 由于我故意制造的无限循环,我的 javascript 代码无法正常工作
- laravel - Laravel 6.12“尚未设置外观根。” 使用日志时::
- authentication - 由于范围无效,Identity Server 4 请求验证失败
- c++ - OpenMP 中并行块外的竞争条件 (ThreadSanitizer);假阳性?
- android - 拥有多个工具栏而无需设置 supportActionBar 或 actionBar?
- java - 如何使用cardView在android中创建可滑动和可点击的卡片?
- vue.js - 为使用 Vue 创建的元素应用 JQuery onclick 方法
- node.js - 为什么我安装了 2 个类似的软件包?
- verilog - 使用 readmemb 初始化内存时,索引参数的顺序是否重要
- python - SQLAlchemy - 如何切片数组以获得完整范围?[:] 编译为 [NULL:NULL]