Skip to content

Instantly share code, notes, and snippets.

@fernyb
Created December 3, 2010 06:17
Show Gist options
  • Save fernyb/726649 to your computer and use it in GitHub Desktop.
Save fernyb/726649 to your computer and use it in GitHub Desktop.
Stomp Client usage example
#define kUsername @"test"
#define kPassword @"user"
#define kQueueName @"/topic/deals"
#define kHost @"localhost"
#define kPort 61613
@implementation YDealsMenuItemController
@synthesize service;
- (void)awakeFromNib
{
CRVStompClient * s = [[CRVStompClient alloc] initWithHost:kHost
port:kPort
login:kUsername
passcode:kQueueName
delegate:self];
[s connect];
NSDictionary *headers = [NSDictionary dictionaryWithObjectsAndKeys:
@"client", @"ack",
@"true", @"activemq.dispatchAsync",
@"1", @"activemq.prefetchSize", nil];
[s subscribeToDestination:kQueueName withHeader: headers];
[self setService: s];
[s release];
}
#pragma mark CRVStompClientDelegate
- (void)stompClientDidConnect:(CRVStompClient *)stompService
{
NSLog(@"** Stomp Service Did Connect");
}
- (void)stompClient:(CRVStompClient *)stompService messageReceived:(NSString *)body withHeader:(NSDictionary *)messageHeader
{
//NSLog(@"gotMessage body: %@, header: %@", body, messageHeader);
//NSLog(@"Message ID: %@", [messageHeader valueForKey:@"message-id"]);
[textField setStringValue:body];
// If we have successfully received the message ackknowledge it.
[stompService ack: [messageHeader valueForKey:@"message-id"]];
}
- (void)dealloc
{
[service unsubscribeFromDestination: kQueueName];
[service release];
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment