我正在连接到 IBM Websphere MQ。我希望能够将回复消息与正确的请求消息相匹配。我已经翻阅了数百页才能得到这个,但没有运气。
我有一个类 - MQHandler - 它将一条消息发送到一个定义的队列,并从另一个队列读取请求。这工作得很好,但是,如果多个用户同时使用该应用程序,消息就会混淆。
我似乎无法在接收器上找到一种方法来指示要匹配的 CorrelationID。就像是...
消费者.接收(选择器);
您可以检查以下方法以确保我正确执行此操作吗?
/**
* When the class is called, this initialisation is done first.
*
* @throws JMSException
*/
public void init() throws JMSException
{
// Create a connection factory
JmsFactoryFactory ff;
try
{
ff = JmsFactoryFactory.getInstance( WMQConstants.WMQ_PROVIDER );
cf = ff.createConnectionFactory();
// Set the properties
cf.setStringProperty( WMQConstants.WMQ_HOST_NAME, hostServer );
cf.setIntProperty( WMQConstants.WMQ_PORT, 1414 );
cf.setStringProperty( WMQConstants.WMQ_CHANNEL, channel );
cf.setIntProperty( WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT );
cf.setStringProperty( WMQConstants.WMQ_QUEUE_MANAGER, qManager );
connection = cf.createConnection(); …Run Code Online (Sandbox Code Playgroud) 最近,我面临着在我们的软件中进行多处理的挑战。我想要一个主进程来生成子进程,并且我需要某种方法将日志信息发送回主进程。这主要是因为我们使用的模块将警告和错误消息写入日志对象,并且我们希望这些消息出现在主进程中运行的 GUI 中。
显而易见的方法是编写一个带有 write() 方法的小类,该方法将 put() 放入队列,然后在日志流处理程序中使用此类。然后主进程将从该队列中 get() 将文本发送到 gui。但这似乎不起作用,我不知道为什么
我编写了一些示例代码来演示该问题。它使用日志对象在子进程中写入队列,然后主进程尝试从队列中读取,但失败。有人可以帮我弄清楚这有什么问题吗?
import time, multiprocessing, queue, logging
class FileLikeQueue:
"""A file-like object that writes to a queue"""
def __init__(self, q):
self.q = q
def write(self, t):
self.q.put(t)
def flush(self):
pass
def func(q):
"""This function just writes the time every second for five
seconds and then returns. The time is sent to the queue and
to a logging object"""
stream = FileLikeQueue(q)
log = logging.getLogger()
infohandler = logging.StreamHandler(stream)
infohandler.setLevel(logging.INFO)
infoformatter = …Run Code Online (Sandbox Code Playgroud) 在一次面试中,我被要求列出目录及其子目录\xc2\xb9中的文件名,而不使用递归,也不使用堆栈或队列。
\n\n由于我知道的唯一非递归方式使用堆栈,因此我无法回答这个问题。
\n\n面试官解释了解决方案,但我无法理解。我唯一记得的是它涉及两种方法而不是一种。
\n\n这种允许在没有递归、没有堆栈或队列的情况下列出目录及其子目录中的文件的方法是什么?
\n\n\xc2\xb9 解决方案与语言无关。子目录列表由ListDirectories(string directoryPath)方法提供,文件由ListFiles(string directoryPath). 我们事先不知道子目录的深度。
我在大学的实时系统课程中使用 ARM 微控制器。在我目前正在进行的项目中,我正在实现矢量场直方图(VFH)算法。
问题是:我需要在线程之间进行通信;更具体地说,我想要一个线程从测距仪获取传感器数据,对其进行必要的转换并将它们存储在队列中。他们,另一个线程必须获取这些数据并处理它,等等。
目前,我正在使用它的一个更简单的版本 - 一个线程从 ADC (SensorAcquisitionHandler) 获取数据,另一个线程将前 5 项(最多)的平均值输出到显示器 (ControlSignalHandler)。
/* Queue used to store data from the rangefinder sensors. */
static unsigned int Sensors[100];
static int SensorsHead = 0;
static int SensorsTail = 0;
void SensorAcquisitionHandler(void) {
/* Clear the interrupt. */
ADCIntClear(ADC0_BASE, 1);
int i; /* Index for the measurements buffer. */
/* There are only 3 rangefinders used. */
if (ADCSequenceDataGet(ADC0_BASE, 1, rangeBuffer) == 3) {
/* Put rangeBuffer's data into SensorDataQueue. */
/* …Run Code Online (Sandbox Code Playgroud) 假设我有一个整数队列,
#include <iostream>
#include <queue>
using namespace std;
int main() {
int firstValToBePushed = 1;
queue<int> CheckoutLine;
CheckoutLine.push(firstValeToBePushed);
cout << CheckoutLine.front();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能使用保存指向整数的指针而不是像上面当前那样的整数来完成基本上相同的事情。我计划创建一个循环来生成多个值,但这只是一个更简单的示例。
谢谢,
这是我在这里发表的第一篇文章,因此如果我不遵守格式规则或其他一般规则,我提前道歉。
我有一个基于 Spring JMS 的客户端应用程序,它使用多个使用者从队列中读取数据。我的限制是:在失败和消息重复检测的情况下保证重新传递。
弹簧配置
<bean id="jndiDestinationResolver" class="org.springframework.jms.support.destination.DynamicDestinationResolver" />
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<constructor-arg ref="MyConnectionFactory" />
<property name="destinationResolver" ref="jndiDestinationResolver" />
<property name="receiveTimeout" value="100" />
</bean>
<bean class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destinationResolver" ref="jndiDestinationResolver" />
<property name="connectionFactory" ref="MyConnectionFactory" />
<property name="destinationName" value="my_Queue" />
<property name="messageListener" ref="MyListener" />
<property name="maxConcurrentConsumers" value="10"/>
<property name="sessionTransacted" value="true"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
我的监听器代码类似于:
protected void processTextMessage(TextMessage textMessage) {
尝试 {
// 处理消息
} catch(异常e){
尝试 {
sendTextMessage("my_Queue",correlationID, textMessage.getText());
} catch (JMSException e1) {
log.error("将消息写回队列时出错!");
抛出 JmsUtils.convertJmsAccessException(e1);
}
}
}
protected void sendTextMessage(字符串队列名称,最终字节[]相关ID,字符串消息){ … 我使用 Redis 服务器来排队工作作业和缓存,并且由于我不希望键冲突,所以我想知道 Python-RQ 使用哪些键名称来存储其数据。
我正在尝试开发一个多租户多数据库应用程序,这基本上意味着每个租户都有自己的数据库、自己的用户、资源等。
当然,当请求进来时,Laravel 需要知道要使用哪个 DB 连接,所以我编写了一个中间件,它基本上解析请求中的 JWT 并查找租户 ID 或用户名,然后简单地连接到租户的数据库。
但是现在我正在使用队列,并且我试图超越连接到主数据库并插入失败作业记录的 laravel 5 的默认行为。
当我深入研究供应商文件时,我发现了一个FailedJobProvider接口:
<?php
namespace Illuminate\Queue\Failed;
interface FailedJobProviderInterface
{
/**
* Log a failed job into storage.
*
* @param string $connection
* @param string $queue
* @param string $payload
* @return void
*/
public function log($connection, $queue, $payload);
/**
* Get a list of all of the failed jobs.
*
* @return array
*/
public function all();
/**
* Get a single failed job.
*
* …Run Code Online (Sandbox Code Playgroud) 有没有除此之外的其他方法来获取队列对象的所有元素?
def method queue
array = []
until queue.empty? do
array << queue.pop
end
array
end
Run Code Online (Sandbox Code Playgroud)
我正在尝试这样的事情:
def method queue
Array(until queue.empty? do queue.pop end)
end
Run Code Online (Sandbox Code Playgroud)
但这会返回一个空数组。
语境
我一直在查看 多处理队列的源代码(请参见此处)Python 2.7并有一些问题。
双端队列用于缓冲区,放入队列的任何项目都会附加到双端队列,但对于 get(),使用管道。
我们可以看到,在 put 期间,如果 feeder 线程尚未启动,它将启动。
该线程将从线程中弹出对象并将它们发送到上述管道的读取端。
问题
那么,为什么要使用双端队列和管道呢?
难道不能只使用双端队列(或任何其他具有 FIFO 行为的数据结构)并同步推送和弹出吗?
同样,难道不能只使用 Pipe 来包装发送和接收吗?
也许我在这里遗漏了一些东西,但是馈线线程弹出物品并将它们放在管道上似乎有点矫枉过正。
queue ×10
python ×3
algorithm ×1
arm ×1
arrays ×1
c ×1
c++ ×1
correlation ×1
ibm-mq ×1
interrupt ×1
jms ×1
laravel ×1
laravel-5 ×1
logging ×1
loops ×1
php ×1
pointers ×1
python-2.7 ×1
python-3.x ×1
recursion ×1
redis ×1
rollback ×1
ruby ×1
spring ×1
spring-jms ×1
stack ×1
transactions ×1
websphere ×1