Skip to content

Instantly share code, notes, and snippets.

@digitalasia
Created January 11, 2014 15:14
Show Gist options
  • Save digitalasia/8372096 to your computer and use it in GitHub Desktop.
Save digitalasia/8372096 to your computer and use it in GitHub Desktop.
method to call the rabbitmq server
-(IBAction) login
{
//publish something
AMQPConnection *connection = [[AMQPConnection alloc] init];
[connection connectToHost:@"pmimitest.cloudapp.net" onPort:5672];
[connection loginAsUser:@"guest" withPassword:@"guest" onVHost:@"/"];
AMQPChannel *channel = [connection openChannel];
//=================================================================================
AMQPExchange *exchange = [[AMQPExchange alloc] initDirectExchangeWithName:@"ToServerv3"
onChannel:channel
isPassive:NO
isDurable:YES
getsAutoDeleted:NO];
AMQPQueue *queue = [[AMQPQueue alloc] initWithName:@""
onChannel:channel
isPassive:NO
isExclusive:NO
isDurable:YES
getsAutoDeleted:NO];
[queue bindToExchange:exchange withKey:@"serverv3"];
//=================================================================================
AMQPChannel *channel2 = [connection openChannel];
AMQPExchange *exchange2 = [[AMQPExchange alloc] initTopicExchangeWithName:@"FromServerv3"
onChannel:channel2
isPassive:NO
isDurable:YES
getsAutoDeleted:NO];
AMQPQueue *queue2 = [[AMQPQueue alloc] initWithName:@""
onChannel:channel2
isPassive:NO
isExclusive:NO
isDurable:YES
getsAutoDeleted:NO];
[queue2 bindToExchange:exchange2 withKey:@"*.ytbryan@gmail.com"];
[queue2 startConsumerWithAcknowledgements:NO isExclusive:NO receiveLocalMessages:YES];
//=================================================================================
NSDictionary *dict=@{@"host": @"pmimitest.cloudapp.net",
@"port":@"5672",
@"username":@"guest",
@"password":@"guest",
@"vhost":@"/"
};
AMQPConsumerThread *thread = [[AMQPConsumerThread alloc] initWithConfiguration:dict exchangeKey:@"FromServerQ_ytbryan@gmail.com" topic:@"FromServerv3" delegate:self callbackQueue:_callbackQueue];
thread.delegate = self;
[thread start];
NSString *jsonMsg = @"{\"method\": \"login\",\"identity\": {\"name\": \"ytbryan\",\"password\": \"hahaha\",\"email\": \"ytbryaniosdev@gmail.com\",\"device_id\": \"\",\"acct_status\": \"\"},\"contacts\": [{\"email\": \"ytbryan@gmail.com\"}]}";
// [exchange publishMessage:jsonMsg usingRoutingKey:@"serverv3"];
[exchange publishMessage:jsonMsg messageID:@"" payloadData:Nil usingRoutingKey:@"serverv3" correlationID:@"" callbackQueue:@""];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment