我正在编写一个使用单个对话框的(C++)应用程序.在设置了消息泵和处理程序后,我开始想知道如何将C++异常传播到我的原始代码(CreateDialogParam例如,调用的代码).
这是我的意思的骨架示例:
BOOL CALLBACK DialogProc(HWND, UINT msg, WPARAM, LPARAM)
{
if(msg == WM_INITDIALOG) //Or some other message
{
/*
Load some critical resource(s) here. For instnace:
const HANDLE someResource = LoadImage(...);
if(someResource == NULL)
{
---> throw std::runtime_error("Exception 1"); <--- The exception handler in WinMain will never see this!
Maybe PostMessage(MY_CUSTOM_ERROR_MSG)?
}
*/
return TRUE;
}
return FALSE;
}
//======================
void RunApp()
{
const HWND dlg = CreateDialog(...); //Using DialogProc
if(dlg == NULL)
{
throw std::runtime_error("Exception 2"); //Ok, …Run Code Online (Sandbox Code Playgroud) 背景: 我们当前的系统涉及两个服务(一个用Java编写,另一个用PHP编写),它们使用HTTP回调相互通信.我们希望使用ActiveMQ(或其他,如果需要)从HTTP回调迁移到基于消息的体系结构.我们可能会使用STOMP在它们之间进行通信.最终,PHP服务将用Java重写,但这不是该项目的一部分.
问题: ActiveMQ系统如何通知PHP已将新消息发布到PHP系统订阅的队列?在当前系统中,回调固有地调用PHP并触发它.这消失了基于消息的架构.
可能的解决方案:
我正在使用Hornetq 2.0我不知道我怎么知道目前有多少消息在队列中.
这是一个非常有用的功能,所以我可以在运行时知道我的消费者是否足够快地消费消息.
我没有使用JMS api,而是使用高度优化的核心API.
获取队列中消息数的正确(最快)方法是什么?
我找到了2路,但不知道这是什么方法.
public int size(){
ClientSession session;
try {
session = sf.createSession(false, false, false);
ClientRequestor requestor = new ClientRequestor(session, "hornetq.management");
ClientMessage m = session.createMessage(false);
ManagementHelper.putAttribute(m, "core.queue." + queueName, "messageCount");
ClientMessage reply = requestor.request(m);
int count = (Integer) ManagementHelper.getResult(reply);
return count;
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
要么
public synchronized int size(){
ClientSession coreSession = null;
int count = 0;
try {
coreSession = sf.createSession(false, false, false);
ClientSession.QueueQuery result;
result = coreSession.queueQuery(new …Run Code Online (Sandbox Code Playgroud) 任何人都可以推荐一个消息队列解决方案,用于.net winforms应用程序,最好是开源.
到目前为止,我们一直使用MSMQ并发现它对我们有效,但应用程序将部署到的环境不受我们对该项目的控制,因此我们无法保证将安装MSMQ,使用该应用程序的人员将不会安装它的知识,我们没有资源在整个过程中谈论它们.
所以我正在寻找类似MSMQ的东西,但可以包含在应用程序安装包中.
我的应用程序在Jboss 7.1.1上运行.我有一个每分钟运行一次的调度程序,需要检查DLQ中是否有消息并在数据库中进行一些更新.
我写了一个消息,消费者听取预定义的自定义DLQ.问题是我可以看到自定义DLQ中有消息但consumer.receiveNoWait()始终返回null.
以下是创建消费者的代码:
/*this is running fine and creating the consumer*/
public DestinationHandlerImpl(ConnectionFactory connectionFactory,
Destination destination, boolean useTransaction, int delMode,
boolean isProducer) throws JMSException {
connection = connectionFactory.createConnection();
consumer = session.createConsumer(destination);
}
Run Code Online (Sandbox Code Playgroud)
这是使用消息的代码(每隔一分钟运行一次):
/*this always return null, event when there are messages in the queue*/
public <T extends BaseEvent> T recieveMessage()
throws JMSException {
Message message = consumer.receiveNoWait(); // ----> always return null!!!
if (message != null && !(message instanceof ObjectMessage)) {
throw new IllegalArgumentException(
"message object …Run Code Online (Sandbox Code Playgroud) 我尝试用VS2008编译这个与boost相关的类(错误行是/**/):
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
#include <boost/interprocess/sync/named_mutex.hpp>
#include <boost/interprocess/sync/named_condition.hpp>
struct SafeShardQueue
{
typedef boost::interprocess::scoped_lock<boost::interprocess::named_mutex> scoped_mutex;
SafeShardQueue()//:
{
}
~SafeShardQueue()
{
remove();
}
void wait_msg()
{
scoped_mutex locker(*mu);
data_avail_condition->wait(locker);
}
void wait_space()
{
scoped_mutex locker(*mu);
queue_empty_condition->wait(locker);
}
boost::shared_ptr<boost::interprocess::message_queue> msgs;
boost::shared_ptr<boost::interprocess::named_condition> data_avail_condition;
boost::shared_ptr<boost::interprocess::named_mutex> mu;
boost::shared_ptr<boost::interprocess::named_condition> queue_empty_condition;
static SafeShardQueue* open()
{
SafeShardQueue* tmp = new SafeShardQueue();
boost::interprocess::open_only_t open_create_type;
/***/tmp->msgs.reset(new boost::interprocess::message_queue (open_create_type, "message_queue"));**
tmp->mu.reset(new boost::interprocess::named_mutex(open_create_type, "shared_queue_mutex"));
tmp->data_avail_condition .reset(new boost::interprocess::named_condition(open_create_type, "data_avail_condition"));
tmp->queue_empty_condition .reset(new boost::interprocess::named_condition(open_create_type, "queue_empty_condition"));
return tmp;
}
static SafeShardQueue* create()
{
remove();
SafeShardQueue* tmp …Run Code Online (Sandbox Code Playgroud) 我有多个现有的应用程序,通过System.Messaging API使用MSMQ发送和接收消息.队列通常是非事务性的,是MSMQ 3和4的混合体.
接收应用程序现在处理有害消息,以便在第一次出现任何异常时将消息放入错误队列以进行手动干预.但事实证明,绝大多数人工干预都只是简单地将消息移回主队列进行另一次尝试,此时它就成功了.因此,为了使该过程自动化,我想向接收器添加重试功能,使得消息被移回给主队列一定次数,每个消息之间有给定的延迟.
我想利用MSMQ开箱即用的任何东西,以及围绕此问题的任何流行或最佳实践模式,而不是重新发明轮子.为此,有很多关于MSMQ 4中对有害消息的额外支持.但它们似乎不容易通过.Net访问.此外,我可以找到使用它们的唯一引用是通过带有MSMQ绑定的WCF.
如果没有使用WCF,任何人都可以建议任何模式或指向实现重试的任何示例吗?
我开发了一个rest api,它接受一些数据并将其存储在消息队列(Redis List)中.现在从redis这个数据被推送到MySQL数据库.问题是客户端需要等到数据写入mysql.
我希望客户端应该等到数据写入消息队列(Redis List),并且将数据推送到MySQL的函数应该异步执行.我该怎么做 ?我的整个代码库都是用PHP编写的,所以我更喜欢用PHP编写代码.
我读过这个,但没试过.
我很困惑如何执行slave.php(在链接中提到).我的意思是当一条新消息到达队列时,slave.php将如何找到它.
我不想为此使用cronjob.相反,当新消息到达时,slave.php应该异步执行.怎么做?
我在互联网上看到很多使用网络套接字和RabbitMQ(https://github.com/videlalvaro/rabbitmq-chat)聊天的例子,但我不明白为什么它需要一个聊天应用程序的消息队列.
为什么不能通过Web套接字将消息从浏览器发送到服务器,然后服务器使用广播方法再次使用Web套接字将该消息广播到其余的活动浏览器?(也许我错过了什么)
伪代码示例(使用socket.io):
// client (browser)
socket.emit("message","my great message that will be received by all"
// server (any server can be, but let's just say that it is also written in JavaScript
socket.on("message", function(msg) {
socket.broadcast.emit(data);
});
// the rest of the browsers
socket.on("message", function(msg) {
// display on the screen the message
});
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种能够使用RabbitMQ调度消息的解决方案,因此不仅要按照多个来源中的描述延迟消息,还要安排它发送消息,例如每天.
如果不是RabbitMQ,你可以想到任何其他解决方案,你建议使用消息总线的微服务环境?所以它真的是关于结合任务调度器和消息总线的概念......
或者使用作业调度程序将消息推送到消息队列更好,例如将rundeck与RabbitMQ结合使用?