我想将我的(嵌入式)ActiveMQ Artemis从1.5.6迁移到2.7.0,但是在开始时我遇到有关日记不兼容的错误。
2019-05-09 17:10:08,762 main org.apache.activemq.artemis.core.server ERROR AMQ224000: Failure in initialisation
java.lang.IllegalStateException: This is using old journal data, export your data and import at the correct version
at org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.loadMessageJournal(AbstractJournalStorageManager.java:912)
at org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.loadJournals(ActiveMQServerImpl.java:2980)
at org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.initialisePart2(ActiveMQServerImpl.java:2690)
at org.apache.activemq.artemis.core.server.impl.LiveOnlyActivation.run(LiveOnlyActivation.java:72)
at org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.internalStart(ActiveMQServerImpl.java:564)
at org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.start(ActiveMQServerImpl.java:501)
at org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl.start(JMSServerManagerImpl.java:376)
at org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS.start(EmbeddedJMS.java:131)
如何在不丢失数据的情况下迁移邮件?
我发现了引入了新格式(https://issues.apache.org/jira/browse/ARTEMIS-1009)的更改,但是没有找到有关如何迁移或如何使用旧格式的信息。
我通过以下方式启动2.7.0服务器:
Configuration configuration = new ConfigurationImpl();
configuration.setJMXManagementEnabled(false);
configuration.setPersistenceEnabled(true);
configuration.setBindingsDirectory(persistenceLocation + "bindings");
configuration.setJournalDirectory(persistenceLocation + "journal");
configuration.setPagingDirectory(persistenceLocation + "paging");
configuration.setLargeMessagesDirectory(persistenceLocation + "largemessages");
configuration.addAddressesSetting("#", new AddressSettings().setAutoCreateJmsQueues(false).setAutoDeleteJmsQueues(false));
configuration.addAcceptorConfiguration("in-vm", "vm://0");
configuration.addAcceptorConfiguration("tcp","tcp://" +host+ ":" + port + "?anycastPrefix=jms.queue.");
configuration.setSecurityEnabled(true);
Set<Role> roles = new HashSet<>();
roles.add(new Role(PRODUCER, true, false, false, false, false, false, false, false, false, false));
roles.add(new Role(CONSUMER, false, true, false, false, false, false, false, false, false, false));
configuration.putSecurityRoles("#", roles);
JMSQueueConfigurationImpl queueConfig = new JMSQueueConfigurationImpl();
queueConfig.setDurable(true);
queueConfig.setName("Provisioning");
JMSConfiguration jmsConfig = new JMSConfigurationImpl();
jmsConfig.getQueueConfigurations().add(queueConfig);
SecurityConfiguration securityConfiguration = new SecurityConfiguration();
securityConfiguration.addUser(user, password);
securityConfiguration.addRole(user, PRODUCER);
securityConfiguration.addRole(user, CONSUMER);
securityConfiguration.setDefaultUser(user);
ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(),
securityConfiguration);
// Start server
EmbeddedJMS server = new EmbeddedJMS();
server.setJmsConfiguration(jmsConfiguration);
server.setConfiguration(configuration);
server.setSecurityManager(securityManager);
server.start()
答案 0 :(得分:0)
您可以使用Artemis data
工具导出和导入日记。
bin
目录。./artemis data exp > /tmp/export.xml
bin
目录。./artemis run
./artemis data imp --input /tmp/export.xml
导入需要运行的代理,并且默认情况下它将尝试连接到localhost:61616
。但是,可以根据需要使用--host
和--port
开关进行更改。
如果您希望直接使用基础Java而不是命令行工具,则可以执行以下操作来导出:
import java.io.ByteArrayOutputStream;
import org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter;
...
ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
XmlDataExporter xmlDataExporter = new XmlDataExporter();
xmlDataExporter.process(xmlOutputStream, "BindingsDirectory", "JournalDirectory", "PagingDirectory", "LargeMessagesDirectory");
System.out.print(new String(xmlOutputStream.toByteArray()));
此操作必须由要导出的日记本机的版本运行,例如,如果要从1.5.6版导出日记,则这些类必须来自1.5.6 jar,因为可以正确读取日记的版本。
要导入,您可以运行以下命令:
import java.io.ByteArrayInputStream;
import org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter;
...
ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
XmlDataImporter xmlDataImporter = new XmlDataImporter();
xmlDataImporter.validate(xmlInputStream);
xmlInputStream.reset();
xmlDataImporter.process(xmlInputStream, session);
这里session
指向您要在其中导入数据的代理实例。
您可以在ActiveMQ Artemis test-suite中看到许多有效的示例。