Skip to content

Commit

Permalink
Merge pull request #268 from laserg/issue-267
Browse files Browse the repository at this point in the history
Provide ability to publish and consume binary data directly
  • Loading branch information
viartemev authored Aug 21, 2019
2 parents bffa8a7 + 99a7b49 commit a73131c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ open class TxChannel internal constructor(private val channel: Channel) : Channe

fun publish(message: OutboundMessage) {
message.apply {
this@TxChannel.channel.basicPublish(exchange, routingKey, properties, msg.toByteArray())
this@TxChannel.channel.basicPublish(exchange, routingKey, properties, msg)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ConfirmPublisher internal constructor(private val channel: Channel) {
continuations[messageSequenceNumber] = continuation
continuation.invokeOnCancellation { continuations.remove(messageSequenceNumber) }
cancelOnIOException(continuation) {
message.run { channel.basicPublish(exchange, routingKey, properties, msg.toByteArray()) }
message.run { channel.basicPublish(exchange, routingKey, properties, msg) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,34 @@ data class OutboundMessage(
val exchange: String,
val routingKey: String,
val properties: BasicProperties,
val msg: String
)
val msg: ByteArray
) {
constructor(
exchange: String,
routingKey: String,
properties: BasicProperties,
msg: String
) : this(exchange, routingKey, properties, msg.toByteArray())

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as OutboundMessage

if (exchange != other.exchange) return false
if (routingKey != other.routingKey) return false
if (properties != other.properties) return false
if (!msg.contentEquals(other.msg)) return false

return true
}

override fun hashCode(): Int {
var result = exchange.hashCode()
result = 31 * result + routingKey.hashCode()
result = 31 * result + properties.hashCode()
result = 31 * result + msg.contentHashCode()
return result
}
}

0 comments on commit a73131c

Please sign in to comment.