Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jms connection status #1252

Merged
merged 9 commits into from
Oct 30, 2018
Merged

Conversation

andreas-schroeder
Copy link
Contributor

This is my proposal for JMS connection status.

Fixes #1251

@andreas-schroeder
Copy link
Contributor Author

This PR extends #1227, don't merge this before the former is merged/approved.

@andreas-schroeder
Copy link
Contributor Author

Finally, travis failed with the test I expeced to fail (due to re-connection failing): https://travis-ci.org/akka/alpakka/jobs/435270299#L690

@andreas-schroeder
Copy link
Contributor Author

Commit 745a6ef fixes an issue in the test mentioned here: #1231 - However, a different error message.

@andreas-schroeder
Copy link
Contributor Author

rebased on top of master

@2m
Copy link
Member

2m commented Oct 6, 2018

I am wondering if exposing a boolean as a connectivity status is useful enough.

An alternative would be to expose a Source[JmsConnectorState, ...] instead. From that it would be possible for the user to create a stream that consumers state changes and updates an atomic reference if that is what is needed.

WDYT?

@andreas-schroeder
Copy link
Contributor Author

The boolean connectivity status would be enough for my use case, as I don't need immediate connectivity updates - having a delay of 1 second would be fine for me.

That said, I see having a stream of connectivity updates could also be beneficial if a fast response to connectivity changes is needed, so let's explore how this could look like.

How would you suggest expose the Source? As part of the materialized value, or by using a fan-out shape in the stage?

@2m
Copy link
Member

2m commented Oct 7, 2018

I think it should be materialized value. Together with a KillSwitch, like you have connectivity status currently.

@andreas-schroeder
Copy link
Contributor Author

Hi @2m, I've spiked the change and one challenge is that the source needs to be pre-materialized, and that can only happen during preStart. Consequently, the source might not be there at the time the materialized value's connected method is called, and I either need to busy wait for the preStart to complete or return a Future[Source[...]]. I like to keep the API simple, but I guess that to stay in line with the non-blocking mantra of Akka, we need to go for the Future - what do you think?

@2m
Copy link
Member

2m commented Oct 7, 2018

How are you building the status source?

If it is, for example, a Source.queue then you can prematerialize the source to get out the materialized value, which now can be passed into the graph stage.

Alternatively, to convert from Future[Source[T, ...]] to Source[T, ...] you can do:

val fs = Future[Source[T, ...]]
val s: Source[T, ...] = Source.fromFuture(fs).flatMapConcat(identity)

@andreas-schroeder
Copy link
Contributor Author

@2m the Future conversion is elegant, will do! 👍It will take me a couple to assemble something to show; the Source and the JmsConnectorState types needs to be Java-ified for the Java-DSL, and the exposed state shouldn't have the JmsConnection exposed either. So there's a couple lines of code to write there.

@andreas-schroeder andreas-schroeder force-pushed the jms-connection-status branch 2 times, most recently from f59e84f to 6896007 Compare October 17, 2018 16:54
@andreas-schroeder
Copy link
Contributor Author

@2m here we go - I rebased on master and squashed everything into one commit. Have a look and tell me what you think.

I will add a couple more tests for connection status, and for correct handling of reconnection failures on each stage (creating connection, session, consumer/producer, and destination).

@andreas-schroeder
Copy link
Contributor Author

Here are some more tests. I was thinking to replace the status update Stopping with Failed and Completed respectively, but that is a bit more effort than just having Stopping. What do you think, @2m ?

@andreas-schroeder
Copy link
Contributor Author

So I went ahead and did the split of "stopping" into "failing" and "completing". I've also updated the docs and updated all factory methods in JmsProducer and JmsConsumer.

For the Java-API, this is a breaking change.
For the Scala-API, this is a non-breaking change.

This PR is complete from my side, please have a look.

Stream-based connection status

  Connection status is now exposed as stream of updates. For the Java
  interface, a Java enum is exposed, for the Scala interface, a sealed
  trait with case objects and a case class is used.

Fix reconnect attempts

  Now also retry to connect (for a limited amount of times and after
  delay) if creating sessions, consumers, producers or destinations fail

Fix flaky 'disconnect exceptional completion' test

  Fixes akka#1231
  Fixes akka#1031
- Add tests for connection status and reconnects on session creation
  failures
- Connecting status attempt number was off-by-one for JmsConsumer
- Session creation failure was not properly handled
- Also made sure that published states are natural: no intermediate
  disconnected state is published on failure
- Also improved logic handling consumer downstream completion
- Also ensured that access to state and state queue is safe
- Added more tests for connection status
- Breaking change: using JmsConsumerControl and JmsProducerStatus in all
  JmsProducer and JmsConsumer factory methods
- Adjusted and extended docs
- Also renamed stage state source to connectorState
- Also fixed flaky test "abort connection on security exception"
- Also simplified openConnection method
- Reverted openConnection simplification, as it did not handle
  exceptions on connection.setExceptionListener
- Added test that demonstrates the simplification was invalid
- Removed unnecessary broker forced restart in Spec
@andreas-schroeder
Copy link
Contributor Author

rebased once more on top of master.

@2m 2m added the api-change label Oct 28, 2018
Copy link
Member

@2m 2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great work @andreas-schroeder!

@andreas-schroeder
Copy link
Contributor Author

Thanks @2m - also for your input, I think this PR wouldn't be in that shape without your ideas.

Copy link
Member

@ennru ennru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

source: stream.scaladsl.Source[jms.scaladsl.JmsConnectorState, NotUsed]
): Source[JmsConnectorState, NotUsed] =
source.map {
case Disconnected => JmsConnectorState.Disconnected
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the Scala states could contain the Java state and offer asJava.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that introduce a dependency from the scaladsl to the javadsl, would that be fine for you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, even if the dependency goes the other direction for most cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented with 6a406b7

@ennru ennru merged commit ba8bee3 into akka:master Oct 30, 2018
@ennru ennru added this to the 1.0-M2 milestone Oct 30, 2018
@ennru
Copy link
Member

ennru commented Oct 30, 2018

Thank you for your continued efforts with the JMS connector.

@andreas-schroeder
Copy link
Contributor Author

Thank you for keeping everything nicely together! Really appreciate the efforts you and your team put into Alpakka.

Btw, this PR also fixed the test failures mentioned in issues #1031 and #1231.

@sullis
Copy link
Contributor

sullis commented Oct 30, 2018

when is the next Milestone release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants