嗨,我正在使用嵌入式代理Qpid测试Spring集成项目。但问题是我如何在qpid中制作队列和交换。我以为rabbit-config.xml会在qpid代理中制作队列和交换,但无济于事。我的流程是在qpid代理中创建队列和交换,将消息传递给它们,绑定到这些队列的入站amqp适配器将收到消息,我可以继续测试
错误:队列:“推送”。顾客阿科纳。控制器。搜索“未在VirtualHost”default上找到”。
qpid-config.json:
{ "name": "EmbeddedBroker", "modelVersion": "2.0", "storeVersion" : 1, "authenticationproviders" : [ {
"name" : "noPassword",
"type" : "Anonymous",
"secureOnlyMechanisms": []
},
{
"name" : "passwordFile",
"type" : "PlainPasswordFile",
"path" : "${qpid.home_dir}${file.separator}src${file.separator}main${file.separator}resources${file.separator}password.properties",
"secureOnlyMechanisms": []
} ], "ports" : [
{
"name": "AMQP",
"port": "${qpid.amqp_port}",
"authenticationProvider": "passwordFile",
"protocols": [
"AMQP_0_10",
"AMQP_0_8",
"AMQP_0_9",
"AMQP_0_9_1"
]
}],
"virtualhostnodes" : [ {
"name" : "default",
"type" : "JSON",
"defaultVirtualHostNode" : "true",
"virtualHostInitialConfiguration" : "${qpid.initial_config_virtualhost_config}",
"storeType" : "DERBY"
}
]
}
暗语属性具有
客人:客人
我为运行测试创建了一个单独的配置文件。这是rabbitmq配置。除此之外,我还有一个兔子上下文xml文件,其中定义了所有队列和交换。
@Configuration
@Profile("qpid")
public class QpidConfig {
String amqpPort = "5672";
//String qpidHomeDir = "complete";
String configFileName = "src/main/resources/qpid-config.json";
@Bean
BrokerOptions brokerOptions() {
File tmpFolder= Files.createTempDir();
//small hack, because userDir is not same when running Application and ApplicationTest
//it leads to some issue locating the files after, so hacking it here
String userDir=System.getProperty("user.dir").toString();
File file = new File(userDir);
String homePath = file.getAbsolutePath();
BrokerOptions brokerOptions=new BrokerOptions();
brokerOptions.setConfigProperty("qpid.work_dir", tmpFolder.getAbsolutePath());
brokerOptions.setConfigProperty("qpid.amqp_port",amqpPort);
brokerOptions.setConfigProperty("qpid.home_dir", homePath);
brokerOptions.setInitialConfigurationLocation(homePath + "/"+configFileName);
return brokerOptions;
}
@SuppressWarnings("rawtypes")
@Bean
Broker broker() throws Exception {
org.apache.qpid.server.Broker broker = new org.apache.qpid.server.Broker();
broker.startup(brokerOptions());
return (Broker) broker;
}
private ConnectionFactory connectionFactory() {
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("admin");
factory.setPassword("admin");
factory.setHost("127.0.0.1");
factory.setPort(5672);
return factory;
}
@Bean(name ="rabbitConnectionFactory")
public CachingConnectionFactory rabbitConnectionFactory(){
return new CachingConnectionFactory(connectionFactory());
}
@Bean(name="rabbitTemplate")
public RabbitTemplate rabbitTemplate(){
return new RabbitTemplate(rabbitConnectionFactory());
}
@Bean(name ="arkonaHeaderMapper")
public DefaultAmqpHeaderMapper syncerHeaderMapper() {
DefaultAmqpHeaderMapper amqpHeaderMapper = DefaultAmqpHeaderMapper.inboundMapper();
amqpHeaderMapper.setRequestHeaderNames("*");
amqpHeaderMapper.setReplyHeaderNames("*");
return amqpHeaderMapper;
}
}
编辑
我的rabbit-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">
<rabbit:queue name="pull.appt.arkona.scheduler.adapter" />
<rabbit:queue name="pull.appt.arkona.adapter.processor" />
<rabbit:queue name="pull.customer.arkona.to.lookup" />
<rabbit:queue name="pull.customer.arkona.lookup.processor" />
<rabbit:queue name="pull.customer.arkona.scheduler.adapter" />
<rabbit:queue name="pull.ro.arkona.to.lookup" />
<rabbit:queue name="pull.ro.arkona.adapter.processor" />
<rabbit:queue name="pull.ro.arkona.scheduler.adapter" />
<rabbit:queue name="pull.closed.arkona.scheduler.adapter" />
<rabbit:queue name="pull.parts.arkona.scheduler.adapter" />
<rabbit:queue name="pull.closed.arkona.adapter.processor" />
<rabbit:queue name="pull.parts.arkona.adapter.processor" />
<rabbit:queue name="pull.vehicle.arkona.to.lookup" />
<rabbit:queue name="pull.vehicle.arkona.lookup.processor" />
<rabbit:direct-exchange name="dms.arkona.exchange" durable="true">
<rabbit:bindings>
<rabbit:binding queue="pull.appt.arkona.scheduler.adapter" key="pull.appt.arkona.scheduler.adapter.key"></rabbit:binding>
<rabbit:binding queue="pull.appt.arkona.adapter.processor" key="pull.appt.arkona.adapter.processor.key"></rabbit:binding>
<rabbit:binding queue="pull.customer.arkona.to.lookup" key="pull.customer.arkona.to.lookup.key"></rabbit:binding>
<rabbit:binding queue="pull.customer.arkona.lookup.processor" key="pull.customer.arkona.lookup.processor.key"></rabbit:binding>
<rabbit:binding queue="pull.customer.arkona.scheduler.adapter" key="pull.customer.arkona.scheduler.adapter.key"></rabbit:binding>
<rabbit:binding queue="pull.ro.arkona.to.lookup" key="pull.ro.arkona.to.lookup.key"></rabbit:binding>
<rabbit:binding queue="pull.ro.arkona.adapter.processor" key="pull.ro.arkona.adapter.processor.key"></rabbit:binding>
<rabbit:binding queue="pull.ro.arkona.scheduler.adapter" key="pull.ro.arkona.scheduler.adapter.key"></rabbit:binding>
<rabbit:binding queue="pull.vehicle.arkona.to.lookup" key="pull.vehicle.arkona.to.lookup.key"></rabbit:binding>
<rabbit:binding queue="pull.vehicle.arkona.lookup.processor" key="pull.vehicle.arkona.lookup.processor.key"></rabbit:binding>
<rabbit:binding queue="pull.closed.arkona.scheduler.adapter" key="pull.closed.arkona.scheduler.adapter.key"></rabbit:binding>
<rabbit:binding queue="pull.closed.arkona.adapter.processor" key="pull.closed.arkona.adapter.processor.key"></rabbit:binding>
<rabbit:binding queue="pull.parts.arkona.scheduler.adapter" key="pull.parts.arkona.scheduler.adapter.key"></rabbit:binding>
<rabbit:binding queue="pull.parts.arkona.adapter.processor" key="pull.parts.arkona.adapter.processor.key"></rabbit:binding>
</rabbit:bindings>
</rabbit:direct-exchange>
</beans>
您的应用程序上下文中是否有RabbitAdmin
?(它检测队列/交换/绑定并在建立连接时声明它们)。
我刚刚用QPID 6.1.2测试了Spring集成AMQP示例,它创建了一切正常。。。
<!-- Infrastructure -->
<rabbit:connection-factory id="connectionFactory" host="xx.xx.xx.xx" virtual-host="default" />
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" />
<rabbit:admin connection-factory="connectionFactory" />
<rabbit:queue name="si.test.queue" />
<rabbit:direct-exchange name="si.test.exchange">
<rabbit:bindings>
<rabbit:binding queue="si.test.queue" key="si.test.binding" />
</rabbit:bindings>
</rabbit:direct-exchange>
编辑
启动应用程序对我来说也很好。。。
@SpringBootApplication
public class So50364236Application {
public static void main(String[] args) {
SpringApplication.run(So50364236Application.class, args);
}
@Bean
public ApplicationRunner runner(RabbitTemplate template) {
return args -> template.convertAndSend("so50364236", "foo");
}
@Bean
public Queue queue() {
return new Queue("so50364236");
}
@RabbitListener(queues = "so50364236")
public void listen(String in) {
System.out.println(in);
}
}
和
spring.rabbitmq.addresses=xx.x.x.x
spring.rabbitmq.virtual-host=default
和
2018-05-16 13:17:25.013 INFO 34714 --- [ main] com.example.So50364236Application : Started So50364236Application in 1.151 seconds (JVM running for 1.579)
foo
我在代理的管理页面上看到了队列。
编辑2
这里是另一个引导应用程序,其中队列在XML文件中声明;使用QPID 6.1.6嵌入。。。
qpid配置。json
{
"name": "EmbeddedBroker",
"modelVersion": "2.0",
"storeVersion": 1,
"authenticationproviders": [
{
"name": "noPassword",
"type": "Anonymous",
"secureOnlyMechanisms": []
},
{
"name": "passwordFile",
"type": "PlainPasswordFile",
"path": "${qpid.home_dir}${file.separator}etc${file.separator}passwd",
"secureOnlyMechanisms": []
}
],
"ports": [
{
"name": "AMQP",
"port": "${qpid.amqp_port}",
"authenticationProvider": "passwordFile",
"protocols": [
"AMQP_0_10",
"AMQP_0_8",
"AMQP_0_9",
"AMQP_0_9_1"
]
}
],
"virtualhostnodes": [
{
"name": "default",
"type": "JSON",
"defaultVirtualHostNode": "true",
"virtualHostInitialConfiguration": "${qpid.initial_config_virtualhost_config}",
"storeType": "DERBY"
}
]
}
配置。xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">
<rabbit:queue name="so50364236b" />
</beans>
application.properties
spring.rabbitmq.addresses=localhost:8888
启动应用程序
@SpringBootApplication
@ImportResource("config.xml")
public class So50364236Application {
public static void main(String[] args) {
new SpringApplicationBuilder(So50364236Application.class)
.web(WebApplicationType.NONE)
.run(args);
}
@Bean
public ApplicationRunner runner(RabbitTemplate template) {
return args -> template.convertAndSend("so50364236b", "foo");
}
@Bean
BrokerOptions brokerOptions() throws Exception {
Path tmpFolder = Files.createTempDirectory("qpidWork");
Path homeFolder = Files.createTempDirectory("qpidHome");
File etc = new File(homeFolder.toFile(), "etc");
etc.mkdir();
FileOutputStream fos = new FileOutputStream(new File(etc, "passwd"));
fos.write("guest:guest\n".getBytes());
fos.close();
BrokerOptions brokerOptions = new BrokerOptions();
brokerOptions.setConfigProperty("qpid.work_dir", tmpFolder.toAbsolutePath().toString());
brokerOptions.setConfigProperty("qpid.amqp_port", "8888");
brokerOptions.setConfigProperty("qpid.home_dir", homeFolder.toAbsolutePath().toString());
Resource config = new ClassPathResource("qpid-config.json");
brokerOptions.setInitialConfigurationLocation(config.getFile().getAbsolutePath());
return brokerOptions;
}
@Bean
Broker broker() throws Exception {
org.apache.qpid.server.Broker broker = new org.apache.qpid.server.Broker();
broker.startup(brokerOptions());
return broker;
}
@RabbitListener(queues = "so50364236b")
public void listen(String in) {
System.out.println(in);
}
}
和
[Broker] BRK-1004 : Qpid Broker Ready
received: foo
也许您正在做一些导致引导的管理员未被声明的事情。不清楚您为什么要添加自己的连接工厂和模板;您是否也尝试添加自己的RabbitAdmin
?
如果要在spring integration jms上为消息发布者创建qpid目标。例如,我可以创建如下队列: 之后,我将此队列设置为通道适配器: 如果发布者发送第一条消息,将在消息代理上创建队列。 但是如果我想动态设置队列,我能做什么呢? 发布者看起来像: } publisher方法的第二个参数是目标的名称。如果我在发送消息之前在brokerside上创建队列,那么这是可行的。我当前的解决方案是
我有一个带有此参数的qpid队列:bus-sync-query--耐用--file-size=48--file-count=64 我想把1000000条消息放到这个队列中。每条消息只是一个包含12个字符的字符串。(002000333222、002000342678等)。我必须将哪些值设置为config--file size=X--file count=Y才能将所有消息放入队列?
问题内容: 他们如何在Java中创建代理。他们是根据需要创建代理,还是创建代理并将其永久保存。 问题答案: 您可以通过两种基本方式创建代理: 通过接口使用JDK机制。看一看。 在具体的类上使用一些字节码生成/操作库。看看cglib和javassist Apache有一个很好的实用程序:commons- proxy 。它包装了许多用于创建代理的机制和框架。 这全部与动态代理有关,即在运行时创建的代理
当谈到JMS队列/主题时,我很困惑。我想要的是消息应该发给每个订阅者,并且我希望订阅者在处于活动状态时从非活动时间接收消息。但是,我无法控制订阅者是否具有持久订阅。有没有办法设置持久队列,并将其设置为每个订阅者都会收到相同的消息?以及如何使用Spring配置进行设置 非常感谢。
我已经创建了代理X,我如何在其中创建10个不同的代理?
我在一家公司实习。我被要求找到一种方法,使用java在其中一个系统中实现snmp代理。我试图为java找到一个免费的MIB编译器,但失败了。因此,我尝试使用SNMP4J agentX库来实现这一点(因为他们明确表示需要主代理和子代理)。我以前从未使用过它,所以我很难实现它。库包中有一个示例主代理和子代理。我不明白如何修改它以包含我自己mib文件中的变量。或者,如果任何人有一个更简单的主代理或子代理