Comments (14)
@garyrussell but Spring's RestTemplate knows how to map generics. It can map anything with help of TypeReference
from spring-amqp.
Would you mind to share all the configuration to play from our side?
Thanks
from spring-amqp.
Let's try to figure out what I have. Sorry, but code is in Kotlin.
Working test:
@Test
fun shouldExceptOnWrongData() {
val deal = secondaryDeal().copy(dealNo = "")
val requestListener = harness.getSpy<DealListener>("deals")
requestListener.validator = validator
val respObject = rabbitTemplate.convertSendAndReceive(props.queueName, deal)
val respString = mapper.writeValueAsString(respObject)
val resp = mapper.readValue<ResponseWrapper<Either<String, ErrorInfo>>>(respString, object : TypeReference<ResponseWrapper<Either<String, ErrorInfo>>>() {})
assertThat(resp.success, `is`(false))
assertThat(resp.payload.isRight(), `is`(true))
assertThat(resp.payload.right().code, `is`(400))
assertThat(resp.payload.right().message, not(isEmptyOrNullString()))
}
Test class:
@SpringBootTest(classes = arrayOf(ITConfig::class))
open class RequestListenerRabbitIT : BaseRabbitIT() {
@Autowired
lateinit var rabbitTemplate: RabbitTemplate
@Autowired
lateinit var harness: RabbitListenerTestHarness
@MockBean
lateinit var dealService: DealService
@Autowired
lateinit var props: DealConfigurationProperties
@Autowired
@Qualifier("getValidator")
lateinit var validator: LocalValidatorFactoryBean
@Autowired
lateinit var mapper: ObjectMapper
BaseRabbitIT:
@ActiveProfiles("rabbitIT")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@RunWith(SpringRunner::class)
abstract class BaseRabbitIT
ITConfig:
@Profile("!test")
@Configuration
@EnableAutoConfiguration(
exclude = arrayOf(
RabbitAutoConfiguration::class
)
)
@ComponentScan(basePackages = arrayOf("ru.sberned.sgr.core"))
open class ITConfig
from spring-amqp.
The Jackson2JsonMessageConverter
can handle "inner" types in standard "containers" (lists, maps etc); it doesn't understand the generic types contained within some kind of user container such as your ResponseContainer
- I believe you will need a custom Jackson2JavaTypeMapper
to help it with typing; you are getting a hash map because Jackson doesn't know the type to convert to .
from spring-amqp.
Perhaps, but the AMQP converter conveys type information in headers and it (currently) only handles containers (collections, arrays, maps, etc).
from spring-amqp.
@garyrussell does it work without __TypeId__
header? It should according to documentation, but your thesis makes me think that I don't understand docs correctly.
Also — is it be possible to add support of TypeReference
to converSendAndRecieve
and recieveAndConvert
methods?
from spring-amqp.
Your code is useless.
I need to see RabbitTemplate
and RabbitListenerContainerFactory
configuration.
It isn't clear by that code how you deal with JSON...
from spring-amqp.
It requires either headers or a custom class mapper/type mapper.
is it be possible to add...
Anything's possible - it's software after all; feel free to open a new feature/improvement JIRA Issue and, of course, contributions are always welcome.
from spring-amqp.
@artembilan
ok, sorry. Here's Rabbit config
@Configuration
@Conditional(TestProfileNotActiveCondition::class)
open class RabbitMQConfig {
@Autowired
lateinit var connectionFactory: ConnectionFactory
@Autowired
lateinit var props: MessagingConfigurationProperties
@Bean
open fun admin() = RabbitAdmin(connectionFactory)
@Bean open fun queue() = Queue(props.deal.queueName, true)
@Bean open fun queueReply() = Queue("${props.deal.queueName}.reply", true)
@Bean
open fun messageConverter(mapper: ObjectMapper) = run {
val result = Jackson2JsonMessageConverter()
result.setJsonObjectMapper(mapper)
result
}
@Bean
open fun contractRequestStateDurableQueue() = Queue(props.event.queueName, true)
@Bean
open fun smsQueue() = Queue(props.sms.queueName, true)
@Bean
@Qualifier("smsChannel")
open fun internalChannel(connectionFactory: ConnectionFactory): Channel {
val channel = connectionFactory.createConnection().createChannel(true)
channel.queueDeclare(props.sms.queueName, true, false, false, null)
val args = HashMap<String, Any>()
args.put("x-delayed-type", "direct")
channel.exchangeDeclare(props.sms.exchangeName, "x-delayed-message", true, false, args)
channel.queueBind(props.sms.queueName, props.sms.exchangeName, "")
return channel
}
}
There is no anything special as you can see.
So everything else is contained in
compile 'org.springframework.boot:spring-boot-starter-amqp'
, which is included with spring-boot 1.4.2
from spring-amqp.
@asm0dey Proof of concept here.
We are about to release our first milestone for 2.0 and this needs a lot more work, so it won't make it into that; we should be able to get something in the next milestone at the end of the year, though.
However, we could make the small change now to the RabbitTemplate
that supports subclassing so you could write your own template subclass.
Would that be useful?
from spring-amqp.
@garyrussell
1st: thank you very mech for PoC. It looks very promising and I'm very glad that you are worknig on it!
2nd: What do you mean when you're speaking about template subclass? That it'll be possible to write RabbitTemplate, which supports generics? With ParametryzedTypeReference I think?
from spring-amqp.
I am just saying we don't have time to get the full solution in the upcoming milestone.
As a work-around, we could go ahead and expose the
protected Message convertSendAndReceiveRaw(...)
method now.
This would allow users to subclass the template like I do in the PoC with just a small amount of code. We could even do that in the next 1.6.x release.
Without that change to the template, you would have to write much more code.
from spring-amqp.
@garyrussell very cool! Thank you, I think it's very good start!
from spring-amqp.
This has been fixed via https://jira.spring.io/browse/AMQP-675
from spring-amqp.
Related Issues (20)
- Get rid of `synchronized` in the `BlockingQueueConsumer`
- Get rid of `synchronized` in `spring-rabbit-test` module
- Get rid of the rest of `synchronized` in the ListenerContainer infrastructure
- Improve Extensibility of RepublishMessageRecovererWithConfirms by supporting SpEL expressions HOT 1
- AmqpRejectAndDontRequeueException completely restarts Consumer HOT 2
- The `SimpleMessageListenerContainer` does not shutdown properly
- The `SimpleMessageListenerContainer` does not shutdown properly HOT 1
- Swallowed exception 'AmqpTimeoutException: No available channels' HOT 4
- Add batchReceiveTimeout in SimpleMessageListenerContainer HOT 3
- MessageProperties setDelay maximum value problem HOT 3
- ImmediateAcknowledgeAmqpException keeps the message in the queue HOT 10
- TraceId propagation to the new thread local HOT 4
- Wrong ClassLoader is used for message deserialization when devtools are active
- Wrong ClassLoader is used for message deserialization when devtools are active HOT 1
- Kotlin suspend functions return type is incorrect HOT 3
- Kotlin suspend functions return type is incorrect HOT 1
- Channel cache leak when no answers from broker for pending confirms
- Channel cache leak when no answers from broker for pending confirms HOT 1
- Invoke RabbitListenerErrorHandler when the batch of the listener is enabled HOT 2
- Document that micrometer observations aren't started for batch listeners HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-amqp.