Skip to content
forked from juretta/objc-stomp

drue's modifications of STOMP Objective-C client to support binary messages with content-length header, plus an NSData interface

License

Notifications You must be signed in to change notification settings

drue/objc-stomp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STOMP client for Objective-C

This is a simple STOMP client based on Stefan Saasen's version of an initial implementation (StompService) from Scott Raymond [email protected] (see http://gist.github.com/72935)

This version differs in that it has been changed to support binary message bodies using the content-length header and an NSData interface. It no longer supports messages with bodies that do not have a content length header. The broker I'm using always sends content-length.

This repo also has an Xcode project with an ios static lib target, plus cocoasyncsocket as a git submodule.

Documentation

http://dev.coravy.com/wiki/display/OpenSource/Stomp+client+for+Objective-C

Usage

Add AsynSocket.{h,m} and CRVStompClient.{h,m} to your project.

MyExample.h

#import <Foundation/Foundation.h>

@class CRVStompClient;
@protocol CRVStompClientDelegate;


@interface MyExample : NSObject<CRVStompClientDelegate> {
	@private
	CRVStompClient *service;
}
@property(nonatomic, retain) CRVStompClient *service;

@end

In MyExample.m

#define kUsername	@"USERNAME"
#define kPassword	@"PASS"
#define kQueueName	@"/topic/systemMessagesTopic"

[...]

-(void) aMethod {
	CRVStompClient *s = [[CRVStompClient alloc] 
			initWithHost:@"localhost" 
					port:61613 
					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(@"stompServiceDidConnect");
}

- (void)stompClient:(CRVStompClient *)stompService messageReceived:(NSData *)data withHeader:(NSDictionary *)messageHeader {
	NSLog(@"gotMessage body: %@, header: %@", data, messageHeader);
	NSLog(@"Message ID: %@", [messageHeader valueForKey:@"message-id"]);
	// If we have successfully received the message ackknowledge it.
	[stompService ack: [messageHeader valueForKey:@"message-id"]];
}

- (void)dealloc {
	[service unsubscribeFromDestination: kQueueName];
	[service release];
	[super dealloc];
}

About

drue's modifications of STOMP Objective-C client to support binary messages with content-length header, plus an NSData interface

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 100.0%