spring-projects / spring-amqp-samples Goto Github PK
View Code? Open in Web Editor NEWSamples for Spring AMQP
Home Page: http://projects.spring.io/spring-amqp/
Samples for Spring AMQP
Home Page: http://projects.spring.io/spring-amqp/
how to create multiple rabbitmq
Hi!
Thank in advance for any help.
I use apache maven 3.3.3 to build stock.
Here is the errors:
[ERROR] Failed to execute goal on project spring-rabbit-stocks: Could not resolve dependencies for project org.springframework.samples.spring:spring-rabbit-stocks:war:2.1.0.RC1: The following artifacts could not be resolved: org.springframework.amqp:spring-amqp:jar:2.1.0.RC1, org.springframework.amqp:spring-rabbit:jar:2.1.0.RC1: Failure to find org.springframework.amqp:spring-amqp:jar:2.1.0.RC1 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project spring-rabbit-stocks: Could not resolve dependencies for project org.springframework.samples.spring:spring-rabbit-stocks:war:2.1.0.RC1: The following artifacts could not be resolved: org.springframework.amqp:spring-amqp:jar:2.1.0.RC1, org.springframework.amqp:spring-rabbit:jar:2.1.0.RC1: Failure to find org.springframework.amqp:spring-amqp:jar:2.1.0.RC1 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
Hello I tried running the sample stocks and got the below error:
[ERROR] Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'marketDataGateway' defined in class path resource [server-messaging.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'rabbitTemplate' of bean class [org.springframework.amqp.rabbit.stocks.gateway.RabbitMarketDataGateway]: Bean property 'rabbitTemplate' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?: org.springframework.beans.NotWritablePropertyException: Invalid property 'rabbitTemplate' of bean class [org.springframework.amqp.rabbit.stocks.gateway.RabbitMarketDataGateway]: Bean property 'rabbitTemplate' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException (BeanWrapperImpl.java:243)
I was today playing with the AMQPAppender for log4j2, (i.e. org.springframework.amqp.rabbit.log4j2.AmqpAppender) and I was not able to find the way to configure a pattern layout for the output log messages when using log4j2.xml as the way to store the configuration. I do need to include the threadname in the log messages sent to RabbitMQ, so I can track properly each execution path after aggregating the logs. I was looking for examples on this, but I could not find any. Is there a way to apply a layout to the rabbitmq log messages via XML config for log4j2, just as it can be done for a Console appender?
Hello!
I've downloaded the project and tried to build. Unfortunately I could not succeeded due to:
project spring-rabbit-stocks: Could not resolve dependencies for project org.springframework.samples.spring:spring-rabbit-stocks:war:1.0.0.BUILD-SNAPSHOT: The following artifacts could not be resolved: org.springframework.amqp:spring-amqp:jar:1.3.0.RC1, org.springframework.amqp:spring-rabbit:jar:1.3.0.RC1: Failure to find org.springframework.amqp:spring-amqp:jar:1.3.0.RC1 in http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
Can you please write what maven repository we should use?
Thanks.
For http://repo.spring.io/repo
i get
{
"errors" : [ {
"status" : 404,
"message" : "Not Found"
} ]
}
see also
<repositories> <repository> <snapshots> <enabled>true</enabled> </snapshots> <id>repository.springframework.maven.all</id> <name>Spring Framework Repository Including Staging</name> <url>http://repo.spring.io/repo</url> </repository> </repositories>
in the pom.xml of spring-rabbit-json
spring-amqp publish message,mqtt subscribe.
I have successfully implemented publish/subscribe.
for example publish :
CachingConnectionFactory cf = new CachingConnectionFactory();
RabbitAdmin admin = new RabbitAdmin(cf);
MessageProperties props = MessagePropertiesBuilder.newInstance()
.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)
.build();
Message message = MessageBuilder.withBody("ok!".getBytes("UTF-8"))
.andProperties(props)
.build();
RabbitTemplate template = admin.getRabbitTemplate();
template.send("amq.topic", "test.*", message);
What do I need to add code,confirm mqtt successfully received a message?
Besides,listen queue remove/add need code
Hi, I ran the example of log4j2 it completes well 3 or 4 times the message delivery, but at the fifth attemp a connection exception is appearing. I'm attaching the stacktrace of the exception, why could be happening this one? I'm using docker to deploy my rabbitmq server.
org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-1.6.0.RC1.jar:?]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:300) ~[spring-rabbit-1.6.0.RC1.jar:?]
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:547) ~[spring-rabbit-1.6.0.RC1.jar:?]
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:90) ~[spring-rabbit-1.6.0.RC1.jar:?]
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:140) ~[spring-rabbit-1.6.0.RC1.jar:?]
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:76) ~[spring-rabbit-1.6.0.RC1.jar:?]
at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1345) ~[spring-rabbit-1.6.0.RC1.jar:?]
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1338) ~[spring-rabbit-1.6.0.RC1.jar:?]
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1314) ~[spring-rabbit-1.6.0.RC1.jar:?]
at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:335) ~[spring-rabbit-1.6.0.RC1.jar:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.redeclareElementsIfNecessary(SimpleMessageListenerContainer.java:1101) [spring-rabbit-1.6.0.RC1.jar:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$700(SimpleMessageListenerContainer.java:95) [spring-rabbit-1.6.0.RC1.jar:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1277) [spring-rabbit-1.6.0.RC1.jar:?]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[?:1.8.0_111]
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[?:1.8.0_111]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:1.8.0_111]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:1.8.0_111]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:1.8.0_111]
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[?:1.8.0_111]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_111]
at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_111]
at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32) ~[amqp-client-3.6.0.jar:?]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:676) ~[amqp-client-3.6.0.jar:?]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:287) ~[spring-rabbit-1.6.0.RC1.jar:?]
... 12 more
Hi,
I'm trying to use spring-rabbit-stocks web application using mvn jetty:run.
When I try to access the application at http://localhost:8080 I have this message:
Error 404 - Not Found. No context on this server matched or handled this request. Contexts known to this server are: /spring-rabbit-stocks ---> org.mortbay.jetty.plugin.Jetty6PluginWebAppContext@9d200de{/spring-rabbit-stocks,C:\projects\spring-amqp-samples\stocks\src\main\webapp}
Trying with http://localhost:8080/spring-rabbit-stocks/ gives this error message:
HTTP ERROR 500 Problem accessing /spring-rabbit-stocks/. Reason: javax.servlet.http.HttpServletResponse.getStatus()I Caused by: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1146) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1023) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
I'm opening a PR to add support to Servlet 3.1.
Hi, I looked at your example of spring-rabbit-global-errorhandler. we already have a custom errorHandler which implements RabbitListenerErrorHandler interface which is configured by @RabbitListener annotation's attribute errorHandler. But this does'nt catch any MessageConversionExceptions. I understand that those are caught by ConditionalRejectingErrorHandler. we want to catch those type of problems and write to database. What's the best way to configure errorHandler to achieve this?
Apologies if this is not the right place to ask this question.
for example, you use
spring.rabbitmq.publisher-confirms: true
spring.rabbitmq.publisher-returns: true
spring.rabbitmq.template.mandatory: true
and there are alsl
spring.rabbitmq.username...password
is there a document reference to all spring.rabbitmq.* ?
java.lang.NoSuchMethodError: org.springframework.core.MethodParameter.nestedIfOptional()Lorg/springframework/core/MethodParameter;
maybe spring version too low(4.2.9);
this method is suported by 4.3
Reproduce steps:
Start latest windows RabbitMQ on localhost:5672
checkout master branch from this project spring-amqp-samples
Go to module log4j2. You can see the spring-boot version should be 2.2.2.RELEASE in log4j2/pom.xml
Run module log4j2. get error log from stdout
main ERROR Appenders contains an invalid element or attribute "RabbitMQ"
main ERROR Unable to locate appender "rabbitmq" for logger config "org.springframework.amqp.samples.log4j2"
Delete exchange log4j2Sample
from RabbitMQ management UI, because default value of durable
in annotation org.springframework.amqp.rabbit.annotation.Exchange
are different between different spring-rabbit
version.
Change spring-boot-starter-parent version in log4j2/pom.xml to 1.5.x.RELEASE (I tested 1.5.3, 1.5.10, 1.5.22), run module log4j2, sample works and you can see log
Log via AmqpAppender: Sun Jan 26 11:08:21 CST 2020
Logs over Log4J AmqpAppender: Log via AmqpAppender: Sun Jan 26 11:08:21 CST 2020
Delete exchange log4j2Sample
from RabbitMQ management UI, because default value of durable
in annotation org.springframework.amqp.rabbit.annotation.Exchange
are different between different spring-rabbit
version.
Change spring-boot-starter-parent version in log4j2/pom.xml to 2.0.0.RELEASE, run module log4j2, get error log
2020-01-26 11:10:31,034 main ERROR Unable to invoke factory method in class org.springframework.amqp.rabbit.log4j2.AmqpAppender for element RabbitMQ: java.lang.ExceptionInInitializerError java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:136)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:958)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:249)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.commons.logging.LogFactory$Log4jLog.(LogFactory.java:199)
at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
at org.springframework.amqp.samples.log4j2.SpringBootAmqpAppenderApplication.(SpringBootAmqpAppenderApplication.java:43)
Caused by: java.lang.ExceptionInInitializerError
at org.springframework.expression.spel.SpelParserConfiguration.(SpelParserConfiguration.java:36)
at org.springframework.expression.spel.standard.SpelExpressionParser.(SpelExpressionParser.java:42)
at org.springframework.amqp.rabbit.core.RabbitTemplate.(RabbitTemplate.java:156)
at org.springframework.amqp.rabbit.log4j2.AmqpAppender.(AmqpAppender.java:120)
at org.springframework.amqp.rabbit.log4j2.AmqpAppender.createAppender(AmqpAppender.java:229)
... 23 more
Caused by: java.lang.NullPointerException
at org.apache.commons.logging.LogFactory$Log4jLog.(LogFactory.java:204)
at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
at org.springframework.core.SpringProperties.(SpringProperties.java:53)
... 28 more
2020-01-26 11:10:31,038 main ERROR Null object returned for RabbitMQ in Appenders.
2020-01-26 11:10:31,043 main ERROR Unable to locate appender "rabbitmq" for logger config "org.springframework.amqp.samples.log4j2"
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.boot.SpringApplication.run(Ljava/lang/Object;[Ljava/lang/String;)Lorg/springframework/context/ConfigurableApplicationContext;
at org.springframework.amqp.samples.log4j2.SpringBootAmqpAppenderApplication.main(SpringBootAmqpAppenderApplication.java:46)
Process finished with exit code 1
In order to avoid port clashes between sender and receivers in the RabbitMQ tutorials project it would be better to have the receiver start on a different port than the sender.
I fixed this on my copy of the application by doing this.
@Profile("receiver")
private static class ReceiverConfig {
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
return (container -> {
container.setPort(8012);
});
}
@Bean
public Tut5Receiver receiver() {
return new Tut5Receiver();
}
Getting this exception when our code in our endpoints trying to communicate with RMQ . We are using cachingConnectionFactory and TopicExchange.
error=org.springframework.amqp.AmqpIOException: java.net.SocketException: Connection timed out (Write failed) at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:63) at org.springframework.amqp.rabbit.connection.RabbitAccessor.convertRabbitAccessException(RabbitAccessor.java:110) at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:968) at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:945) at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:470) at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:535) at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:522)
D:\spring-github>mvn exec:java -Dexec.classpathScope=test -Dexec.mainClass=org.springframework.amqp.rabbit.stocks.Server &
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Spring AMQP Hello World
[INFO] Spring Rabbit Stocks
[INFO] Spring AMQP log4j
[INFO] Spring AMQP Samples
[WARNING] The POM for com.springsource.bundlor:com.springsource.bundlor.maven:jar:1.0.0.M1B is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for com.springsource.bundlor:com.springsource.bundlor.maven:1.0.0.M1B: Plugin com.springsource.bundlor:com.springsource.bundlor.maven:1.0.0.M1B or
one of its dependencies could not be resolved: Failure to find com.springsource.bundlor:com.springsource.bundlor.maven:jar:1.0.0.M1B in http://nexus.xxx.aaaa:8080/nexus/content/groups/public/
was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Spring AMQP Hello World 1.4.3.RELEASE
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.springsource.bundlor:com.springsource.bundlor.maven:jar:1.0.0.M1B is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for com.springsource.bundlor:com.springsource.bundlor.maven:1.0.0.M1B: Plugin com.springsource.bundlor:com.springsource.bundlor.maven:1.0.0.M1B or
one of its dependencies could not be resolved: Failure to find com.springsource.bundlor:com.springsource.bundlor.maven:jar:1.0.0.M1B in http://nexus.xxx.aaaa:8080/nexus/content/groups/public/
was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:java (default-cli) @ spring-rabbit-helloworld ---
[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6.
[WARNING]
java.lang.ClassNotFoundException: org.springframework.amqp.rabbit.stocks.Server
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:281)
at java.lang.Thread.run(Thread.java:744)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Spring AMQP Hello World ............................ FAILURE [ 0.665 s]
[INFO] Spring Rabbit Stocks ............................... SKIPPED
[INFO] Spring AMQP log4j .................................. SKIPPED
[INFO] Spring AMQP Samples ................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.322 s
[INFO] Finished at: 2015-03-14T17:56:24+08:00
[INFO] Final Memory: 10M/174M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java (default-cli) on project spring-rabbit-helloworld: An exception occured while executing the Java class. org.springfr
amework.amqp.rabbit.stocks.Server -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
hello do you have a sample that covers https://docs.spring.io/spring-amqp/reference/htmlsingle/#direct-reply-to
request reply pattern as described in the link above?
There is now a future that can be used instead of latches.
See https://stackoverflow.com/questions/58902366/rabbitmq-publisher-confirm/58903020#58903020
In the chapter of Reference Manual said:
properties.setXDelay(15000);
when this method doesn't exists.
The correct method is (setDelay):
/**
* Set the x-delay header.
* @param delay the delay.
* @SInCE 1.6
*/
public void setDelay(Integer delay) {
if (delay == null || delay < 0) {
this.headers.remove(X_DELAY);
}
else {
this.headers.put(X_DELAY, delay);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.