-
Notifications
You must be signed in to change notification settings - Fork 583
Add lambda-based methods to consume messages #252
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
This file contains hidden or 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,42 @@ | ||
// Copyright (c) 2017 Pivotal Software, Inc. All rights reserved. | ||
// | ||
// This software, the RabbitMQ Java client library, is triple-licensed under the | ||
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2 | ||
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see | ||
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL, | ||
// please see LICENSE-APACHE2. | ||
// | ||
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, | ||
// either express or implied. See the LICENSE file for specific language governing | ||
// rights and limitations of this software. | ||
// | ||
// If you have any questions regarding licensing, please contact us at | ||
// [email protected]. | ||
|
||
package com.rabbitmq.client; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Callback interface to be notified of the cancellation of a consumer. | ||
* Prefer it over {@link Consumer} for a lambda-oriented syntax, | ||
* if you don't need to implement all the application callbacks. | ||
* @since 5.0 | ||
* @see DeliverCallback | ||
* @see Channel#basicConsume(String, boolean, String, boolean, boolean, Map, DeliverCallback, CancelCallback) | ||
* @since 5.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface CancelCallback { | ||
|
||
/** | ||
* Called when the consumer is cancelled for reasons <i>other than</i> by a call to | ||
* {@link Channel#basicCancel}. For example, the queue has been deleted. | ||
* See {@link Consumer#handleCancelOk} for notification of consumer | ||
* cancellation due to {@link Channel#basicCancel}. | ||
* @param consumerTag the <i>consumer tag</i> associated with the consumer | ||
* @throws IOException | ||
*/ | ||
void handle(String consumerTag) throws IOException; | ||
|
||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,37 @@ | ||
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2 | ||
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see | ||
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL, | ||
// please see LICENSE-APACHE2. | ||
// | ||
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, | ||
// either express or implied. See the LICENSE file for specific language governing | ||
// rights and limitations of this software. | ||
// | ||
// If you have any questions regarding licensing, please contact us at | ||
// [email protected]. | ||
|
||
package com.rabbitmq.client; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* Callback interface to be notified when a message is delivered. | ||
* Prefer it over {@link Consumer} for a lambda-oriented syntax, | ||
* if you don't need to implement all the application callbacks. | ||
* @see CancelCallback | ||
* @see Channel#basicConsume(String, boolean, String, boolean, boolean, Map, DeliverCallback, CancelCallback) | ||
* @since 5.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface DeliverCallback { | ||
|
||
/** | ||
* Called when a <code><b>basic.deliver</b></code> is received for this consumer. | ||
* @param consumerTag the <i>consumer tag</i> associated with the consumer | ||
* @param message the delivered message | ||
* @throws IOException if the consumer encounters an I/O error while processing the message | ||
*/ | ||
void handle(String consumerTag, Delivery message) throws IOException; | ||
|
||
} |
This file contains hidden or 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,55 @@ | ||
// Copyright (c) 2017 Pivotal Software, Inc. All rights reserved. | ||
// | ||
// This software, the RabbitMQ Java client library, is triple-licensed under the | ||
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2 | ||
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see | ||
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL, | ||
// please see LICENSE-APACHE2. | ||
// | ||
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, | ||
// either express or implied. See the LICENSE file for specific language governing | ||
// rights and limitations of this software. | ||
// | ||
// If you have any questions regarding licensing, please contact us at | ||
// [email protected]. | ||
|
||
package com.rabbitmq.client; | ||
|
||
/** | ||
* Encapsulates an arbitrary message - simple "bean" holder structure. | ||
*/ | ||
public class Delivery { | ||
private final Envelope _envelope; | ||
private final AMQP.BasicProperties _properties; | ||
private final byte[] _body; | ||
|
||
public Delivery(Envelope envelope, AMQP.BasicProperties properties, byte[] body) { | ||
_envelope = envelope; | ||
_properties = properties; | ||
_body = body; | ||
} | ||
|
||
/** | ||
* Retrieve the message envelope. | ||
* @return the message envelope | ||
*/ | ||
public Envelope getEnvelope() { | ||
return _envelope; | ||
} | ||
|
||
/** | ||
* Retrieve the message properties. | ||
* @return the message properties | ||
*/ | ||
public AMQP.BasicProperties getProperties() { | ||
return _properties; | ||
} | ||
|
||
/** | ||
* Retrieve the message body. | ||
* @return the message body | ||
*/ | ||
public byte[] getBody() { | ||
return _body; | ||
} | ||
} |
This file contains hidden or 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
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.
Can
equals
andhashCode
be defined in here to support mocking? The same question could be said for https://github.com/rabbitmq/rabbitmq-java-client/blob/master/src/main/java/com/rabbitmq/client/Return.java which was recently added.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 that's a good idea but we can do it in a follow-up PR (feel free to look into a pull request ;))
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.
Sounds good, I'll try and put one together.