向 Amazon SQS 发送 XML 消息
我是 Amazon SQS 和 ruby on Rails 的新手。我正在开发一个项目,一些 XML 消息必须发送到 SQS。我该怎么做?
现在我在 .save 之后的控制器
def create
@thing = Thing.new(params[:thing])
respond_to do |format|
if @thing.save
message = @thing.to_xml
和模型中
inputqueue.send_message(message)
都有这个,这是我可以将 XML 文件发送到 SQS 的方式吗?
I am a newbie to Amazon SQS and ruby on rails. And i am working on a project that some XML messages must be send to SQS. How do i do that?
Now i have this in the controller after the .save
def create
@thing = Thing.new(params[:thing])
respond_to do |format|
if @thing.save
message = @thing.to_xml
and in the model
inputqueue.send_message(message)
Is this the way i can send an XML file to SQS or??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否完全理解,但让我试着弄清楚这一点。每次创建特定模型时,您都想向 Amazon SQS 发送 XML 消息吗?如果是这种情况,那么...
保持控制器不变:
然后,您将使用 Observer 向亚马逊拨打电话。将观察者放在模型目录中:
您的观察者可能看起来像这样:
观察者中的代码将在每次创建后运行。如果观察者中的after_create返回false,则整个创建将回滚,就好像它从未发生过一样。
您可能需要编辑环境配置才能让观察者触发,具体取决于您的应用程序当前的设置方式。
I'm not sure I understand exactly, but let me try and get this straight. Every time you create a particular model, you'd like to send an XML message off to Amazon SQS? If that's the case, then...
keep your controller as so:
Then, you'll use an Observer to make the call to Amazon. Put your observer right inside your models directory:
Your observer might look something like:
The code in the observer will be run after every create. If the after_create in the observer returns false, the entire create is rolled back, as if it never happened.
You might have to edit your environment config to get the observer to fire though, depending on how your application is currently set up.
RightAws::SqsGen2.queue(queue_name, message) 是发送消息的正确方法。
RightAws::SqsGen2.queue(queue_name, message) is the right way to go for sending the message.