pulsar-java-spring-boot-starter icon indicating copy to clipboard operation
pulsar-java-spring-boot-starter copied to clipboard

WIP: Added transactional support to configuration.

Open majusko opened this issue 4 years ago • 3 comments

majusko avatar May 19 '21 20:05 majusko

I review your code, and have a question: how do we use transaction? Your code just enable transaction, but do not add fuction to use it. this project just provide PulsarTemplate to send message, not support transaction.

in pulsar offical java demo here is example:

Transaction txn = pulsarClient
        .newTransaction()
        .withTransactionTimeout(5, TimeUnit.MINUTES)
        .build()
        .get();
//producer
producer.newMessage(txn).value("Hello Pulsar Transaction".getBytes()).sendAsync();
txn.commit().get();

//consumer
Message<byte[]> message = consumer.receive();
consumer.acknowledgeAsync(message.getMessageId(), txn);
txn.commit().get();

Wanxp avatar Jun 25 '21 03:06 Wanxp

Hi @Wanxp , I still didn't design the way how the transaction will work. This PR is just about to make the configuration work and so people can use raw pularClient in case they wish to implement transactions alongside the library. I realised some issue during testing so didn't merge but left the PR so I won't forget to check it again. Feel free to contribute and suggest some way it would work. Thank you for your code, it makes sense to me how the transaction works so I think it won't be that complicated to implement it.

majusko avatar Aug 16 '21 11:08 majusko

Ideally, this should be tied to the @Transactional scope of Spring. The way it works for JMS (if not using JTA) is by registering a callback at TransactionSynchronizationManager (if a transaction is active at all) so the message will only be sent if the enclosing transaction (e.g. database) committed.

grubeninspekteur avatar Apr 06 '22 06:04 grubeninspekteur