如何使队列在HornetQ 2.2.5核心客户端中持久化?

2024-01-02

我想在核心 hornetQ 客户端中创建持久队列。问题是当我停止服务器时,队列和数据将被破坏。如何让队列持久化? 我的代码是:

import java.util.Date;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientConsumer;
import org.hornetq.api.core.client.ClientMessage;
import org.hornetq.api.core.client.ClientProducer;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ClientSessionFactory;
import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.api.core.client.ServerLocator;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory;
import org.hornetq.core.remoting.impl.invm.InVMConnectorFactory;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.HornetQServers;

public class EmbeddedExample
{

   public static void main(final String[] args)
   {
      try
      {

         // Step 1. Create the Configuration, and set the properties accordingly
         Configuration configuration = new ConfigurationImpl();
         configuration.setPersistenceEnabled(false);
         configuration.setSecurityEnabled(false);

         configuration.getAcceptorConfigurations().add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));

         // Step 2. Create and start the server
         HornetQServer server = HornetQServers.newHornetQServer(configuration);
         server.start();

         // Step 3. As we are not using a JNDI environment we instantiate the objects directly
         ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(InVMConnectorFactory.class.getName()));
         ClientSessionFactory sf = serverLocator.createSessionFactory();        

         // Step 4. Create a core queue        
         ClientSession coreSession = sf.createSession(false, false, false);      

         final String queueName = "queue.exampleQueue";

         coreSession.createQueue(queueName, queueName, true);


         coreSession.close();

         ClientSession session = null;

         try
         {

            // Step 5. Create the session, and producer
            session = sf.createSession();

           ClientProducer producer = session.createProducer(queueName);

            // Step 6. Create and send a message
            ClientMessage message = session.createMessage(true);

            final String propName = "myprop";

            message.putStringProperty(propName, "Hello sent at " + new Date());

            System.out.println("Producer:");
            System.out.println("StartDate: "+new Date());
             for (int i = 0; i < 100000; i++)
             {  
                   message = session.createMessage(true); // move it   
                    message.putStringProperty(propName, "Message: " + i);
                    producer.send(message);       
             }
            System.out.println("EndDate: "+new Date());
            // Step 7. Create the message consumer and start the connection
            ClientConsumer messageConsumer = session.createConsumer(queueName);

            session.start();

            // Step 8. Receive the message.
            System.out.println("Consumer:");
            System.out.println("StartDate: "+new Date());

            //for (int i = 0; i <= 100000; i++)         
             int i=0;
            while(true)
            {   
                 i++;
                 if(i == 10000){    
                     i=0;
                     session.start();
                     System.out.println("EndDate: "+new Date());                        
                 }
                 ClientMessage messageReceived = messageConsumer.receive(5000);
                 if (messageReceived!=null) messageReceived.acknowledge();
                 //System.out.println(messageReceived.getStringProperty(propName));
            }

         }
         finally
         {
            // Step 9. Be sure to close our resources!
            if (sf != null)
            {
               sf.close();
            }

            // Step 10. Stop the server
            server.stop();
         }
      }
      catch (Exception e)
      {
         e.printStackTrace();
         System.exit(-1);
      }
   }
}

如果禁用持久性,则不会有持久性:

Configuration configuration = new ConfigurationImpl();
configuration.setPersistenceEnabled(true); <<<<  Make this true

UnsatisfiedLinkError 可能是因为您选择 AIO 并且 LD_LIBRARY_PATH 上没有本机库,请设置 Journal 或使本机库在 Linux 系统中可用。

configuration.setJournalType(JournalType.NIO);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使队列在HornetQ 2.2.5核心客户端中持久化? 的相关文章

  • 具有 async/await 风格函数的 async.queue

    我正在尝试创建一个函数 该函数从对象数组构建队列 然后通过调用多个函数来处理每个对象 处理函数是异步函数 在需要排队之前 我使用异步 等待模式实现了这些函数 我认为这是必要的 因为每个都依赖于前一个的输出 并且我不想有大量嵌套的 Promi
  • Python 中内置最大堆 API

    默认 heapq 是最小队列实现 想知道是否有最大队列的选项 谢谢 我尝试使用 heapify max 作为最大堆的解决方案 但如何动态处理推送 弹出元素 看来 heapify max 只能在初始化时使用 import heapq def
  • Keras 的 OrderedEnqueuer 是否保证了批次的顺序?

    我有一个习惯keras utils sequence它以特定 且关键 的顺序生成批次 但是 我需要跨多个核心并行化批量生成 名字是不是 OrderedEnqueuer 意味着结果队列中批次的顺序保证与原始队列的顺序相同keras utils
  • 使用 Monit 监控 Laravel 队列工作线程

    我目前正在考虑从 Supervisor 迁移到 Monit 以监视 Laravel 队列工作人员 主要原因是能够监视 CPU 内存和设置电子邮件警报 据主管说 我必须安装另一个软件包 因为我希望尽快监视其他内容 例如 Redis 或许还有
  • 帮助尝试理解圆形数组中的模运算

    我有一个小问题试图弄清楚模运算是如何计算的 我正在建立一个队列 所以我有一个圆形数组 我无法弄清楚这个模运算是如何工作的 给定 q 一个 5 个元素长度的字符数组 MAX 常量给出数组的最大长度 5 rare 是一个 int 代表数组 q
  • 使用队列进行基数排序

    我想创建一个基数排序 http en wikipedia org wiki Radix sort使用队列实现 我无法弄清楚我的代码的哪一部分有问题或者我应该阅读哪些资源 我的代码可能完全错误 但这是我的实现 没有任何帮助 我还没有参加数据结
  • 优雅地实现 ExecutorServices 的队列长度指示器

    为什么 哦 为什么不java util concurrent为其提供队列长度指标ExecutorService是 最近我发现自己在做这样的事情 ExecutorService queue Executors newSingleThreadE
  • 如何在Linux中找到处理器队列长度

    尝试确定 Linux 计算机上的处理器队列长度 准备运行但当前未运行的进程数 Windows 中有一个针对此指标的 WMI 调用 但对 Linux 不太了解 我正在尝试挖掘 proc 和 top 以获取信息 有没有办法确定CPU的队列长度
  • HornetQ 重启后不会保留消息

    我使用 HornetQ 作为队列提供程序 因为它具有持久性功能 但是 在我重新启动应用程序后 队列中的所有消息都会丢失 也许是配置问题 这是代码 Step 1 Create the Configuration and set the pro
  • 使用 Celery 创建动态队列

    这是我的场景 当用户登录我的网站时 我会为给定用户排队一堆任务 通常每个任务需要 100 毫秒 每个用户有 100 多个任务 这些任务排队到默认的 Celery 队列中 并且我有数百个工作线程正在运行 当任务在后端完成时 我使用 webso
  • 使用 Javascript 进行速率限制并将 ajax 调用排队为每 15 秒一次

    我有一个应用程序 每次用户执行某些操作时都会自动发送推文 如果用户愿意 可以轻松地每秒执行一次该操作 Twitter 的速率限制表示 它关注 15 分钟内发生了多少条推文 从技术上讲 我认为我总是低于 15 分钟标记 但 Twitter 似
  • RabbitMQ 上的 Nack 和拒绝

    我想处理消费者从队列中获取的不成功的消息并将它们重新排队 想象一下我有这样的情况 P gt foo bar baz gt C 其中 foo bar 和 baz 是消息 如果消费者读到baz但出了问题 我可以使用basic reject or
  • Azure 有害队列计数警报规则

    在之前的一个项目中 我设法设置了一个警报规则 该规则会查看有害队列消息计数 并在队列中存在某些内容时 每天一次 使用 webhook 向 slack 发出警报 我试图找到它在 Azure 中的位置 因为看起来事情已经发生了变化 如果这不是
  • Spring Web 连接到嵌入 Jboss 服务器 7.1.1 的 HornetQ JMS

    我正在尝试设置 spring web 以通过以下方式连接到远程 Jboss 7 1 1 HornetQ JMSthis http java dzone com articles connecting spring地点 但我收到以下错误 是否
  • C# 创建函数队列

    我写了一个名为 QueueManager 的类 class QueueManager Queue functionsQueue public bool IsEmpty get if functionsQueue Count 0 return
  • 如何获取队列中的第 n 个项目?

    我的应用程序中有许多队列和优先级队列 我想轻松访问这些队列中的第 n 个项目 但没有看到使用 API 实现此目的的简单方法 我想我可以创建一个Iterator并迭代到第 n 个元素或使用toArray index 但似乎应该有一个更简单的方
  • 如何自定义BlockingQueue的阻塞行为

    我想创建一个阻塞队列 它根据自定义规则而不是队列中的项目数量来阻止生产者 例如 生产者生成一些文件并放入队列中 消费者经过一番分析后将它们转移到特定位置 对于上述场景 如果队列中的总文件大小达到某个阈值 我希望生产者等待生成新文件 如果总大
  • OutOfRangeError(请参阅上面的回溯):FIFOQueue '_1_batch/fifo_queue' 已关闭并且元素不足(请求 32,当前大小 0)

    我在使用队列中张量流读取图像时遇到问题 请让我知道我犯了什么错误 下面是代码 import tensorflow as tf slim tf contrib slim from tensorflow python framework imp
  • Laravel:运行队列:在 Windows Azure Web App 上连续监听

    我觉得问这个问题有点傻 但我似乎无法在互联网上找到这个问题的答案 经过几个小时的搜索后 我发现在 Linux 服务器上 您使用 Supervisor 在您的网站上连续运行 php artisanqueue listen 无论有或没有守护进程
  • java中队列的实现

    在 Java 中实现队列是一个非常常见的面试问题 我在网上冲浪 看到了许多实现 他们做了一些奇特的事情 比如实现队列接口和编写自己的addLast and removeFirst 方法 我的问题是我不能使用LinkedList 类并使用其预

随机推荐