-
Notifications
You must be signed in to change notification settings - Fork 647
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
MQTT streaming: SourceQueue backpressure #1577
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e445205
mqtt streaming - introduce a mechanism to use SourceQueue backpressure
longshorej c7a0ed2
Harden test
huntc a925fe2
Don’t let WatchedActorTerminatedException fail the session streams
huntc 930046b
Mima exclude; improve toString
ennru 3d9c2aa
Scalafmt
ennru e096ddb
Rename MiMa excludes file to the latest released version
2m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
mqtt-streaming/src/main/mima-filters/1.0.2.backwards.excludes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# PR #1577 | ||
# https://github.com/akka/alpakka/pull/1577 | ||
ProblemFilters.exclude[DirectMissingMethodProblem]("akka.stream.alpakka.mqtt.streaming.MqttSessionSettings.this") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
mqtt-streaming/src/main/scala/akka/stream/alpakka/mqtt/streaming/impl/QueueOfferState.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2016-2019 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
|
||
package akka.stream.alpakka.mqtt.streaming.impl | ||
|
||
import akka.actor.typed.Behavior | ||
import akka.actor.typed.scaladsl.Behaviors | ||
import akka.stream.QueueOfferResult | ||
|
||
private[mqtt] object QueueOfferState { | ||
|
||
/** | ||
* A marker trait that holds a result for SourceQueue#offer | ||
*/ | ||
trait QueueOfferCompleted { | ||
def result: Either[Throwable, QueueOfferResult] | ||
} | ||
|
||
/** | ||
* A behavior that stashes messages until a response to the SourceQueue#offer | ||
* method is received. | ||
* | ||
* This is to be used only with SourceQueues that use backpressure. | ||
*/ | ||
def waitForQueueOfferCompleted[T](behavior: Behavior[T], stash: Seq[T]): Behavior[T] = | ||
Behaviors | ||
.receive[T] { | ||
case (context, completed: QueueOfferCompleted) => | ||
completed.result match { | ||
case Right(QueueOfferResult.Enqueued) => | ||
stash.foreach(context.self.tell) | ||
|
||
behavior | ||
|
||
case Right(other) => | ||
throw new IllegalStateException(s"Failed to offer to queue: $other") | ||
|
||
case Left(failure) => | ||
throw failure | ||
} | ||
|
||
case (_, other) => | ||
waitForQueueOfferCompleted(behavior, stash = stash :+ other) | ||
} | ||
.orElse(behavior) // handle signals immediately | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I'm not clear on are the semantics here. Note that on L43, we catch all events that flow. Thus, the intention is that all signals go to
behavior
but nothing else (until we hit L34 in the future)If
behavior
's signal handler (i.e. the behavior being run viaorElse
) returnsBehavior.same
, I'd like to clarify that it doesn't change the behavior of the actor to itself, i.e.waitForQueueOfferCompleted
(L26-L46) remains the behavior. Hopefully my question makes sense..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the behaviour would indeed remain the same i.e. stay as per the behaviour of
waitForQueueOfferCompleted
. But I've not yet proved this.However, given L46 with the
orElse
, I'm not seeing the signal handler ofbehavior
being applied. When I run the tests I see aDeathPactException
which means that there is no signal handler forTerminated
, but there is such a signal handler forbehavior
...